Question by
BloodMarked · Jan 31, 2018 at 01:28 PM ·
animatornetworkbug-perhapsbug report
[possible Bug] NetworkAnimator only synchronizes first animation layer
when using the NetworkAnimator to synchonize my Animator, only the first Animation Layer is Synchronized. which is a bit awkard because i use the second layer for walking animations.
am i missing something / is only one layer supported or is this a bug?
thers no mention of layers in the Manual / ScriptingApi.
furthermore, can i replicate the NetworkAnimator behaviour for the second layer in a script?
Comment
Answer by BloodMarked · Jan 31, 2018 at 05:19 PM
this is the custom script i made to synchronize animation layers via network. there you can select which layer to synchronize or add more layers.
any recommendations for optimizations etc hugely appreciated
using System.Collections;
using UnityEngine;
using UnityEngine.Networking;
public class simpleNetworkTester : NetworkBehaviour {
Animator anim;
[SyncVar (hook = "OnServerVarUpdate")]
float XPos = 0f;
[SyncVar]
int animStateHash;
[SyncVar]
float animStateTime;
void Start(){
anim = GetComponent<Animator> ();
}
void Update () {
if (!isLocalPlayer)
return; //only do input and logic on the own player
Vector3 newPos = transform.position;
newPos.x += Input.GetAxis ("Horizontal")*.1f;
transform.position = newPos;
AnimatorStateInfo animSI = anim.GetCurrentAnimatorStateInfo (0);
CmdUpdateServerVars (newPos.x, animSI.fullPathHash, animSI.normalizedTime);
}
void OnServerVarUpdate(float newValue){
if (isLocalPlayer)
return; //do not apply changes on own player
Vector3 syncPos = transform.position;
syncPos.x = newValue;
transform.position = syncPos;
anim.Play (animStateHash, 0, animStateTime);
}
[Command(channel = 1)] //send it through the default unreliable channel
void CmdUpdateServerVars(float newXPos, int _animStateHash, float _animStateTime){
XPos = newXPos;
animStateHash = _animStateHash;
animStateTime = _animStateTime;
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612151650im_/https://answers.unity.com/themes/thub/images/avi.jpg)