So I am working on trying to understand the NetworkAnimator and have tried it in 2 different projects; one worked flawlessly, the other didn’t. Yet they both use almost the same code.
On the project that isn’t working, I put the NetworkAnimator on the player, dragged my animator in and then I ticked all the parameters (to true).
I am using this code to change animation:
private void Update()
{
if(isLocalPlayer)
{
float x = Input.GetAxisRaw("Horizontal");
float y = Input.GetAxisRaw("Vertical");
playerAnimation.AnimateMovement((int)x, (int)y);
}
}
The animator is setup with a Blend Tree with 2D simple using x and y float parameters which based on their value plays a certain animation.
UNET’s NetworkAnimator is buggy. It doesn’t sync things properly for 2 reasons.
1: The NetworkIdentity can sometimes bug out the Animator initialization. Things like Animator.SetFloat will fail https://fogbugz.unity3d.com/default.asp?898387_m1dp0u9neo5qlsa4
2: Any animations on layers other than the base animation layer do not sync.
Unsure if your bug is related to those 2, but bottom line is NetworkAnimator… and UNET in general… is extremely buggy. I ended up having to write a custom network animator as a workaround… you may have to do the same.
Ah, now I get why this isn’t working. It is most likely number 2. All my animations are in blend trees which means a second layer. Way to go Unity! >.<
Sure. The part that is really screwing me up (and I’m not sure how to fix other than scrap UNET entirely) is that simply attaching a NetworkIdentity to an object screws up the Animator initialization. Even if you don’t use NetworkAnimator!
I speculate it’s something to do with how UNET disables objects until their “spawned”. But it’s random/intermittent (i.e. I have 100 prefabs in the scene and 80 bug out, and 20 initialize the Animator just fine… even though their all the same prefab!).
That is extremely weird. I never had that when trying to sync animation. Of course it is only one object I am dealing with. However I know for a fact a few people are using UNet and syncing animation with hundreds of objects and it is working well no problems on that end.
The question is, even if UNet disables objects until spawn, why would that mess with your Animator component? It shouldn’t happen.
What happens if you disable/enable the component in the scene after you spawn them?