Search Unity

Question Animations using Netcode for GameObjects

Discussion in 'Animation' started by Boof, Feb 28, 2023.

  1. Boof

    Boof

    Joined:
    Aug 11, 2014
    Posts:
    10
    I rifled through the limited resources for NGO and found nothing helpful for animations in a 3D project. I equipped my project with ParrelSync for testing and managed to get the player transforms to work. On a single client I can see the player model running around with correct animations, but when I check the other client I do not see any animations. Adding a NetworkAnimator to the GameObject that has the Animator attached to it did not help.

    Sorry that it's the crappiest gif ever... You can see at the end of the gif the player is moving away from the camera and they are not doing the running animation. Their legs are just wiggling back and forth... The lighting sucks because I'm making a dark game and need the scene dark to test lighting.

    This is how my hierarchy and inspector look. The GameObject that has the Animator component is a child, and its parent is the one whose Transform is actually being translated in space. I suspect this might have something to do with it, but I'm not sure.


    The root object, "Player Prefab" has a ClientNetworkTransform and a NetworkObject component attached to it:


    Please let me know if you have any ideas on how to solve this problem, or if you know of any helpful tutorials that specifically cover animation for NGO.
     
  2. Boof

    Boof

    Joined:
    Aug 11, 2014
    Posts:
    10
    I think I got this mostly resolved... I removed the Client Network Transform component from the root object and replaced it with a Network Transform component. Then I restructured my scripts that move the root object so that the movement works over the network. I added a Network Animator component to the GameObject which has the Animator attached to it and replaced all instances of
    Code (CSharp):
    1. ...
    2. character.animator.SetTrigger("Stuff");
    3. ...
    to
    Code (CSharp):
    1. ...
    2. if (character.networkAnimator != null) character.networkAnimator.SetTrigger("Stuff");
    3. else character.animator.SetTrigger("Stuff");
    4. ...
    where
    character.networkAnimator
    is just a reference to the Network Animator component. I did identical changes to lines which say
    ResetTrigger
    instead of
    SetTrigger
    .

    I hope this helps whoever may stumble onto it. Some resources that really helped me a lot were:

    https://docs-multiplayer.unity3d.com/netcode/current/components/networkanimator
     
  3. Boof

    Boof

    Joined:
    Aug 11, 2014
    Posts:
    10
    Actually, the real solution I think was to use the Owner-authoritative version of NetworkAnimator, which is the same as "client-authoritative" behavior:
    Code (CSharp):
    1.     public class OwnerNetworkAnimator : NetworkAnimator
    2.     {
    3.         protected override bool OnIsServerAuthoritative()
    4.         {
    5.             return false;
    6.         }
    7.     }