Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

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