Skip to content

NetworkAnimator.Play() is not correctly sending the correct clip info to clients. #428

@nsparisi

Description

@nsparisi

General
Unity version: 2022.3.4f1
Fish-Networking version: 3.7.7
Discord link: https://discord.com/channels/424284635074134018/1034477094731784302/1132020003651194910

Description
On a server-authoritative NetworkAnimator component, the Play() functionality is sending the wrong data to clients.
I believe this is a one-line fix in NetworkAnimator.cs on line 1186.

public void Play(int hash, int layer, float normalizedTime)
{
    if (!_isAnimatorEnabled)
        return;
    if (_animator.HasState(layer, hash))
    {
        _animator.Play(hash, layer, normalizedTime);
        _animator.Update(0f); // !! bug fix !!
        _unsynchronizedLayerStates[layer] = new StateChange();
    }
}

Reason: The when using Unity's Animator.Play() the state does not change right away. You need to wait a frame before accessing the clip data i.e. from _animator.GetCurrentAnimatorStateInfo() .See https://forum.unity.com/threads/resolved-animator-getcurrentanimatorstateinfo-0.1406722/

Replication
Steps to reproduce the behavior:

  1. Make a simple gameobject with Animator and NetworkAnimator attached.
  2. On server-side, call NetworkAnimator.Play(); passing in animation clip names, or hashes, etc.
  3. Observe client-side behavior. The clip will be lagged, 1 animation clip behind the server.

Expected behavior
Calling NetworkAnimator.Play("clip name"); on the server should play "clip name" on the client.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Resolved Pending ReleaseIssue is resolved and will be available on the noted version.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions