Search Unity

How do you allow animations to interrupt each other?

Discussion in 'Animation' started by strich, Mar 24, 2015.

  1. strich

    strich

    Joined:
    Aug 14, 2012
    Posts:
    374
    I'm trying to create a simple set of animations in a single Mecanim controller. I have setup transition paths from Any State to each of the animations. They all fire off and transition between each other fine. However they only transition when they've reached the end of their own animation clip, whereas I require a quick transition between each of the animations at any point in their animation clip timeframe.

    How do I do this?
     
    gibsonluke85 and krlozadan like this.
  2. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    If you are using 5.0 simply uncheck Has Exit Time on your transition, this will allow the transition to be trigger at any time while playing your state.
     
  3. SamTheT

    SamTheT

    Joined:
    Feb 21, 2015
    Posts:
    4
    I found an answer that kind of works.
    Make an Idle animation (and all the other animations that you need)
    Put them into the animator
    Connect "any state" to, for example, jumping and then connect jumping to Idle animation
    Then connect Walking animation to Idle and back.
    Now, you should be able to walk and jump any time you want. Walking animation will be terminated.

    Another theoritical solution is to connect "any state" to all the animations, except Idle, and then connecting all those animations to Idle. idk if it works

    p.s: if you didn't understand anything from what I said, just ask for a screenshot
     
    Monogrid likes this.
  4. strich

    strich

    Joined:
    Aug 14, 2012
    Posts:
    374
    Thanks for the feedback. Yeah I eventually worked out the exact same solution through bruteforce attempts. :)
     
    Creepernuke likes this.
  5. narcis355

    narcis355

    Joined:
    May 30, 2016
    Posts:
    1
    You my friend are a life savior... i think i searched for this in tutorials for a clue for almost 1 h, thank you friend
     
    Nick_Laza and RobbyT15 like this.
  6. GameEverything

    GameEverything

    Joined:
    Feb 22, 2016
    Posts:
    10
    Sorry to bring up a dead thread, but this helped me, too. I bought a series of animations from the Asset Store and they all had exit time checked which was a major headache because waiting for an animation to end would involve a whole bunch of timing and seemingly redundant code. I was like, 'Nah, this can't be how it's done.'

    Thanks.
     
    Nick_Laza and RobbyT15 like this.
  7. RobbyT15

    RobbyT15

    Joined:
    Jan 8, 2015
    Posts:
    4
    Thank God for this comment. Had I not found it, I'd probably be trying to figure this out five years from now. Makes sense since Has Exit Time is the first condition checked.
     
  8. RickshawDerpyDerp

    RickshawDerpyDerp

    Joined:
    Nov 6, 2018
    Posts:
    25
    Turning off "Has exit time" does not allow the next animation to interrupt the animation that is currently playing.
     
  9. HonoraryBob

    HonoraryBob

    Joined:
    May 26, 2011
    Posts:
    1,214
    It doesn't work for me either, even though I'm using 5.0 and I've set AnyState to link to another clip when a parameter has a certain value. Isn't there any way to interrupt an animation clip?
     
  10. Inxentas

    Inxentas

    Joined:
    Jan 15, 2020
    Posts:
    278
    I've never had issues with removing Exit Time to ensure state changes happen immediately. Technically this is not an "interruption" but simply allowing for immediate state changes. My best guess is that there something else blocking the transition from happening, like a trigger that has already been consumed.

    I prefer to work with floats and bools for this and a few other reasons (animation blending mainly). I also find it a little easier to visually debug in the Animator.
     
    the_0dium likes this.
  11. Kechy

    Kechy

    Joined:
    May 21, 2020
    Posts:
    2
    After some time I found a solution that might work for you as well, call the animation from code using Play("name"), then in Animator, make a transition from your animation state to Idle state, in transition settings, Has exit time should be on, make exit time 0.1, and transition duration 0.9, with the rest of the options being default ones without any additional conditions. Hope it helps you as well!
     
    Kububbis likes this.
  12. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    animator.Play and animator.CrossFade can go directly to any state regardless of what transitions you have made.
     
    the_0dium likes this.
  13. the_0dium

    the_0dium

    Joined:
    Nov 29, 2018
    Posts:
    15
    If you uncheck "has exit time" and transitions don't fire immediately, you guys should really check your code. As suggested before, you are probably using triggers in a wrong way or it might be another mistake. In any case your problem is in the code.
     
    rc82 likes this.
  14. mcgilljoshy2

    mcgilljoshy2

    Joined:
    Dec 14, 2023
    Posts:
    1
    Thanks so much I've looked for the answer to this a couple times and never found out how. This solution works seamlessly
     
  15. Destriarch

    Destriarch

    Joined:
    Feb 18, 2020
    Posts:
    6
    I recently animated a talking animation loop that had to interrupt quickly when the character shuts up. Here's how my animator is set up:

    Screenshot 2024-04-12 at 10.44.27 am.png

    'Talk' is a looping animation a second long. I also set up a Boolean parameter called 'IsTalking' to control when it played.

    Transition from Any State -> Talk:
    • Has Exit Time: False
    • Transition Duration: 1
    • Interruption Source: Current State
    • Can Transition to Self: False
    • Conditions: IsTalking = True
    • All other settings default
    Transition from Talk -> Exit
    • Has Exit Time: False
    • Transition Duration: 0.25
    • Conditions: IsTalking = False
    Now, when I want the character to speak, I switch my control scheme to a special one I made called 'Cutscene'. This prevents the player from using any controls other than the 'continue' button. I then call `animator.SetBool("IsTalking", true)` and wait for player input. Once the character is done talking I call `animator.SetBool("IsTalking", false)` and switch back to my main control scheme.

    This seems to be working OK for me. When I set the boolean to false, he stops talking almost immediately (with an intentional 0.25 second animation blend back to the default state to make it nice and smooth - you can remove this if you like by changing the exit transition's duration.)