Search Unity

Defining transition evaluation order

Discussion in 'Animation' started by Newcomma, Jul 20, 2016.

  1. Newcomma

    Newcomma

    Joined:
    Feb 10, 2015
    Posts:
    89
    I have two transitions, one from state A to state B and one from the 'Any State' node to state B.

    I want the machine to consider the transition A -> B before it considers the transition 'Any State' -> B. However it appears that the AnyState transition is checked and fires first.

    Is there anyway to define this order of transition checks so I can prioritise the transition of A -> B first?
     
  2. SethMeshko

    SethMeshko

    Joined:
    Sep 20, 2014
    Posts:
    109
    To explain this I am going to use the actual situation that I did to fix this. It will help to have the real names of the animations to understand the logic. I had a situation where I wanted a pivot to be considered first before deciding whether to just start walking forward or do the pivot from an idle state. It just kept going from the idle to the walk animation.

    To fix that I made a pivot substate that the idle animation always exited to with no transition to the walk state from the idle state. In the pivot state I had a single frame of animation from the beginning of the pivot animation that had a potential transition out to the walk state and a potential transition to the complete pivot state. In that single frame I made the transition dependent on a parameter value that was defined by the angle of the joystick. In this way I forced unity to make a decision between continuing with the pivot and exiting to the walk.

    You don't necessarily have to have the substate, that's just a matter of housekeeping. You could do the single frame "decision state" directly out of the idle. It is important that you set up your transitions correctly. You probably don't want an exit time on either transition. You just want it to be controlled by the parameter.
     
  3. Newcomma

    Newcomma

    Joined:
    Feb 10, 2015
    Posts:
    89
    Thanks for the response. If I'm understanding your solution correctly then your compromise is to have one frame of animation in your pivot state to allows you to blend (or transit) to either of the two anims you want to move into.

    Unfortunately although in my OP I gave a very simplified version of my animation graph where I need to do this kind of decision making (or prioritisation) over many states rather than just one branch which would make this fairly hard to wield. And also require loads of single frame anims for each transition.

    Also ideally I don't want to incur that one frame delay.
     
  4. SethMeshko

    SethMeshko

    Joined:
    Sep 20, 2014
    Posts:
    109
    State machines by design are intended to have a sort of flow chart of actionable states. As far as I know if you want one state to be exited to from another it must have a transition. I think the only way you could get around that so that there was an overriding animation for every state would be to have a layered animation state machine.
     
  5. DavidGeoffroy

    DavidGeoffroy

    Unity Technologies

    Joined:
    Sep 9, 2014
    Posts:
    542
    AnyState transitions are evaluated first by design. In order to work properly, they must supercede everything else.

    In general, it's better to replace an AnyState transition with an explicit call to Animator.Crossfade.

    This does pretty much the same thing, but at least it's possible to track all the places in the code where it's invoked, whereas AnyState transitions can happen literally anytime.

    The more AnyState transitions you have in your state machines, the harder it will become to predict your state machine's behaviour