Search Unity

Bug NetworkAnimator causes StateMachineBehaviours to get called twice.

Discussion in 'Netcode for GameObjects' started by Kyperr, Jan 25, 2022.

  1. Kyperr

    Kyperr

    Joined:
    Jul 15, 2016
    Posts:
    32
    As title says. I have the following StateMachineBehaviour that informs my script of when an animation is done:
    Code (CSharp):
    1.  override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    2.     {
    3.         if (NetworkManager.Singleton.IsServer)
    4.         {
    5.             animator.gameObject.GetComponentInChildren<Whatever>().AttackFinished();
    6.         }
    7.     }
    When the NetworkAnimation is enabled, this fires twice.
    When the NetworkAnimation is disabled, it works as intended (only once).
     
  2. tamshlaw

    tamshlaw

    Unity Technologies

    Joined:
    May 19, 2021
    Posts:
    1
    Hi, I've been trying to reproduce your issue without success. I created an animation controller and some animations. I attached a StateMachineBehaviour to one of the animations with code in OnStateExit & OnStateEnter. Both behave for me exactly as expected. Each is fired once per machine per transition. The NetworkAnimator itself doesn't invoke these functions; they are triggered by the animation. I even tried to force an animation to play twice, but the controller guards against that.

    Can I assume from your code that you are seeing the firing happening twice on the server?

    We haven't done a lot to NetworkAnimator, but just in case can you re-test off of the 'develop' branch of the repo?

    And/or, can you help me with a reproducer that I could run?
     
  3. Kyperr

    Kyperr

    Joined:
    Jul 15, 2016
    Posts:
    32

    Hi Sorry,

    Life got busy, so my project was put on pause for a bit. I apologize for not responding. I am still getting this behavior in pre6. I would love to help you reproduce this. If you would like, you can DM me with a meeting or discord invite and I can screenshare to demo this issue with you. Visually, it appears as if it is causing the OnStateExit to also be called on OnStateEnter
     
  4. imitater967

    imitater967

    Joined:
    Mar 13, 2024
    Posts:
    1
    I have the same issue with netcode 1.8.0, client authority mode, network animator.
    The host mode,the host works fine,
    this problem occurs on both host and server mode, and only the client side,

    when client side plays the shot animation, the state behavior will execute twice on server

    Input.GetMouseButtonDown (once) -> Animator.SetBool (once) -> (Twice) StateBehavior::OnStateEntered


    the animator.setBool is executed when networkvariable changed

    for example.
    I started an server(not host) and a client.
    then attack,
    then client: once -> once -> once
    the server: once-> once -> twice
    Input.getMBD ->Animator.SetBool ->StateBehavior::OnStateEntered
     
    Last edited: Mar 24, 2024