-
-
Notifications
You must be signed in to change notification settings - Fork 207
NetworkAnimator.Play() is not correctly sending the correct clip info to clients. #428
Description
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:
- Make a simple gameobject with Animator and NetworkAnimator attached.
- On server-side, call NetworkAnimator.Play(); passing in animation clip names, or hashes, etc.
- 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.