Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Can't sync animation with NetworkAnimator

Discussion in 'Multiplayer' started by Vallar, Sep 30, 2017.

  1. Vallar

    Vallar

    Joined:
    Oct 18, 2012
    Posts:
    177
    Hello everyone,

    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:

    Code (CSharp):
    1. private void Update()
    2. {
    3.      if(isLocalPlayer)
    4.      {
    5.         float x = Input.GetAxisRaw("Horizontal");
    6.         float y = Input.GetAxisRaw("Vertical");
    7.         playerAnimation.AnimateMovement((int)x, (int)y);
    8.       }
    9. }
    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.

    Any ideas why this isn't working?
     
  2. Zullar

    Zullar

    Joined:
    May 21, 2013
    Posts:
    651
    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.
    https://forum.unity.com/threads/multiple-animation-layer-network-animator-broken.403223/

    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.
     
    Last edited: Oct 4, 2017
  3. Vallar

    Vallar

    Joined:
    Oct 18, 2012
    Posts:
    177
    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! >.<

    Thanks for the tip!
     
  4. Zullar

    Zullar

    Joined:
    May 21, 2013
    Posts:
    651
    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!).
     
  5. Zullar

    Zullar

    Joined:
    May 21, 2013
    Posts:
    651
    If it is issue #2 I bug reported it in May 2016. The dev's repro'd the bug but marked it as postponed.
     
    nxrighthere likes this.
  6. Vallar

    Vallar

    Joined:
    Oct 18, 2012
    Posts:
    177
    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?