Interrupt a State Machine

I´ve made an state machine to have multiple random Idles. The problem is that when the character jumps, dies, walks or any other action, the random idle animations (that are inside the state macine) dont stop inmidiately, they continue untill they end.

1 Like

On your transitions out of the Idle states, make sure that “Has Exit Time” is not checked. That will allow the animation to be interrupted and the state exited at any point.

I tried it but the animations don’t play when I do that.

Same problem here. Since all states within the substate don’t have an exit condition (why should they), one can not uncheck “Has Exit Time”. I’m stumped on this one as well. even setting interruption sources don’t work.

If your animations are not playing, it’s because your transitions need at least one condition, otherwise they will always be taken, and your animation will never play.

To transition between states, you can (in order of maintainability):

  • Trigger a transition between the states
  • Call Animator.CrossFade or Animator.Play to force a dynamic transition between states
  • Trigger an AnyState transition

Otherwise, there’s no way to transition.

2 Likes

Thanks David

To clarify DavidGeoffroy’s response:

What worked for me is:
On the base layer add transition from AnyState to animation that should break the SubStateMachine.

Example
If my SubStateMachine is named RandomIdleMachine then I want my animations like Attack,Jump etc break from RandomIdleMachine, so outside of SubStateMachine(on the base layer) I had to add transition from AnyState to Attack animation.