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. Let us know your feedback about the Global Illumination changes in the 2023.2 beta.
    Dismiss Notice
  3. Dismiss Notice

Inconsistency in StateMachineBehaviour?

Discussion in 'Unity 5 Pre-order Beta' started by WendelinReich, Dec 15, 2014.

  1. WendelinReich

    WendelinReich

    Joined:
    Dec 22, 2011
    Posts:
    228
    The new tutorial for StateMachineBehaviours says:
    • The AnimatorStateInfo is the current info for the state that the state machine behaviour is on. It is the equivalent of writing animator.GetCurrentStateInfo(layerIndex); This can be useful in operations that involve the normalised time of the clip.
    I've noticed that this isn't always true. In my project, the following code prints the debug message up to 12 frames in a row:
    Code (CSharp):
    1.     override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    2.     {
    3.         if (animator.GetCurrentAnimatorStateInfo(layerIndex).shortNameHash != stateInfo.shortNameHash)
    4.             Debug.Log("Inconsistent AnimatorStateInfos...");
    5.     }
    6.  
    Unfortunately, this is in a project from which I'm not currently able to file bug reports. But it seems to me that this is a small bug that should be easy to find and fix.
     
  2. p87

    p87

    Joined:
    Jun 6, 2013
    Posts:
    318
    Create a new project, create a dummy animator and state machine behaviour, and submit as bug report... for fastest fix.

    maybe message @Mecanim.Dev
     
  3. p87

    p87

    Joined:
    Jun 6, 2013
    Posts:
    318
    Last edited: Dec 16, 2014
  4. Mecanim-Dev

    Mecanim-Dev

    Unity Technologies

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    Thx WendelingReich for pointing out this issue

    We will do some investigation and see if we can repro on our side too.

    Best regards,
     
    WendelinReich and p87 like this.
  5. Mecanim-Dev

    Mecanim-Dev

    Unity Technologies

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    After further investigation this is expected, you cannot use animator.GetCurrentAnimatorStateInfo like this. Here the reason

    Let say you have a controller with 2 State A and B with a transition from A to B and you have a StateMachineBehaviour (SMB) on state B only. When your SMB will start to get is first callback OnStateEnter, it does mean that the StateMachine is doing a transition between A to B, so in this case B is the next state, to correctly validate that both AnimatorStateInfo are equivalent you should use animator.GetNextAnimatorStateInfo.

    This is exactly why we did add AnimatorStateInfo as a parameter to all callback. Remove some complexity to handle such case.

    Best regards
     
  6. WendelinReich

    WendelinReich

    Joined:
    Dec 22, 2011
    Posts:
    228
    I see. So parameter 'stateInfo' always refers to the state to which 'this' SMB is attached?
     
  7. Mecanim-Dev

    Mecanim-Dev

    Unity Technologies

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    Yes, basically just before we do call your callback we do query the StateInfo for you and pass it as a parameters to the callback.