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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Interrupt a State Machine

Discussion in 'Animation' started by Happygallo, May 19, 2016.

  1. Happygallo

    Happygallo

    Joined:
    Aug 27, 2014
    Posts:
    4
    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.
    Screen Shot 2016-05-19 at 3.26.04 PM.png Screen Shot 2016-05-19 at 3.25.52 PM.png
     
    Pawciu likes this.
  2. TrickyHandz

    TrickyHandz

    Joined:
    Jul 23, 2010
    Posts:
    196
    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.
     
  3. Happygallo

    Happygallo

    Joined:
    Aug 27, 2014
    Posts:
    4
    I tried it but the animations don't play when I do that.
     
  4. hexagonius

    hexagonius

    Joined:
    Mar 26, 2013
    Posts:
    98
    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.
     
  5. DavidGeoffroy

    DavidGeoffroy

    Unity Technologies

    Joined:
    Sep 9, 2014
    Posts:
    542
    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.
     
    Pawciu and theANMATOR2b like this.
  6. Pawciu

    Pawciu

    Joined:
    Jun 21, 2015
    Posts:
    15
    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.