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. Dismiss Notice

StateMachineBehaviour OnStateXYZ functions

Discussion in 'Animation' started by Def0r, Mar 6, 2015.

  1. Def0r

    Def0r

    Joined:
    Mar 6, 2015
    Posts:
    1
    Hello,
    I'm currently on 5.0.f04
    I'd like to know more about OnStateXXX functions on StateMachineBehaviour class. The documentation is rather thin about it.
    I use behaviour classes to place my game/animation logic into because it's neat and I don't need to have my own separate state machine running (as I did in Unity4). For this purpose, however, I need to know exactly when OnStateEnter / OnStateExit function are called.

    OnStateEnter, for example, as documentation says, is "Called on the first Update frame when a statemachine evaluate this state". Other documentation page says: "OnStateEnter is called on the first frame of the state being played."

    Let's have the following scenario:

    State A, State B. State A plays a looping animation.. State B plays a one-shot animation. We have a transition A->B with a trigger condition. We have a transition B->A with an exit time condition.

    Now, what happens if A->B transition is _longer_ then state B animation?
    Exit-time condition to do B->A transition is true even before A->B transition is finished. Is it?
    If yes and B->A transition begins then what happens to A state behaviour? Is OnStateEnter called when, in fact, state A is still blended (A->B transition didn't finish yet!).
    Either the first nor the second documentation description doesn't provide an answer.

    From my current testing, OnStateEnter and OnStateExit is called unreliably and I think it is just because the situation mention above. OnStateEnter is not called.

    Do you have any experience with this?
    Is there any better documentation about this topic?
    Thank you.

    -Martin
     
  2. Mecanim-Dev

    Mecanim-Dev

    Unity Technologies

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    No matter what are the condition on transition B->A you can only have one transition at a time occuring.
    So in this case transition A->B need to finish first, since the transition A->B is longer than animation B and B in not looping, B normalized time should be 1 and so transition B->A should start on the next frame.