Search Unity

Animator sub-state clarification

Discussion in 'Animation' started by DJHays616, Jul 25, 2016.

  1. DJHays616

    DJHays616

    Joined:
    Feb 23, 2014
    Posts:
    28
    Hi Guys,

    Quick question, I am doing directional based attacks so I made a sub-state for physical attacks. When it goes into the sub-state there are 7 transitions it could do because there are up/down atks. All of the transitions in the physical attack sub-state transition to the exit node after the attack is through. My question is does this return to the entry node of the base layer or do I have to define where it should go through conditions? Also is it better/worse to use the up node over the exit node, and does that effect things transition wise?
     
  2. DavidGeoffroy

    DavidGeoffroy

    Unity Technologies

    Joined:
    Sep 9, 2014
    Posts:
    542
    You need to connect transitions from your sub state machine.
    Those transitions are separate from the transitions in the exit node, and have their own conditions.

    To be safe, you should always have at least one transition that has no condition on your state machine, so you can control where the state machine transitions to if all else fails.

    When the sub state machine decides to transition out through the exit node, all the transitions out of your sub state machine are evaluated.

    If none is valid, the state machine will immediately transition to the default state for this layer (because it has to transition somewhere). I believe there's a warning in the console when that happens.


    As for using the Up node...

    the OnStateMachineEnter and OnStateMachineExit callbacks are not attached to the state machine itself, but to the transitions. This means that if you don't use the entry or exit nodes, these callbacks will not get fired.

    There is nothing preventing you from using the Up node, but if you have every state manage its own transitions in there, you lose a bit of the abstraction that the sub state machine gives you. It'll still work as a way to visually organize your states, but it won't be as useful to manage the "stateness" of your sub state machine.

    It's up to you really.
     
  3. IgorAherne

    IgorAherne

    Joined:
    May 15, 2013
    Posts:
    393
    But it doesn't seem to work :/

    I have two nested stateMachines. When a state in the deepest stateMachine gets to the exit node, it seems to exit ALL parent state machines as well...

    I would expect it to use the parent stateMachine's transitions which would decide where the parent's stateMachine should transition. For example, when the child statemachine hits exit node, this "parent statemachine" could then use an empty transition from itself to its own exit node.

    But instead, the upper-most parent state machine behaves as if it hit the exit node at simultaneously with its child stateMachine.

    Is it an intended behavior, and am I misunderstanding on StateMachine vs SubStateMachine?

    @Mecanim-Dev

    currently on Unity 5.5.0f3


    Edit:

    Upgraded to 5.5.2, same thing happens
     
    Last edited: Feb 25, 2017
  4. IgorAherne

    IgorAherne

    Joined:
    May 15, 2013
    Posts:
    393