Search Unity

Cancel/Interrupt Mecanim transitions?

Discussion in 'Animation' started by Oconim, Feb 28, 2014.

  1. Oconim

    Oconim

    Joined:
    Feb 6, 2014
    Posts:
    3
    Hello, I have currently set up two blend trees in Mecanim. One is for when the character is moving normally and the other is the player in a crouched state when the player holds down the shift key. When the player releases the shift key they should return to the standard state. Everything is working normally except for when the player presses or releases the shift key mid transition. What I want to happen is for the state transition to get canceled out and return as soon the boolean changes however the state does not return until the transition in mecanim is completed. Even though in mecanim it shows that the boolean has changed back to false it still goes through with the state transition before going back to standard with another transition. I've read in the documentation that unchecking atomic allows transitions to be interrupted however even after unchecking them the transitions still go through completely before changing again.

    $mecanim.png

    Is there something else I need to do? Is the atomic parameter a pro only feature or am I misunderstanding the purpose of the atomic parameter? I haven't seen any solutions posted, is there a term I should be looking for specifically? :confused:

    Thank you.
     
  2. Alf203

    Alf203

    Joined:
    Dec 7, 2012
    Posts:
    461
    I have the same problem and I have atomic unchecked also, but mine was when animating color material. Even if I cancel while it is transiting, it still reaches the state it was going to and only then it goes back to the previous state.

    This is a long shot, but try having any state transition to both your regular and crouch states. Maybe its possible that a transition is considered any state ?

    Here is my thread but never got any replies. Hopefully you will get some.

    http://forum.unity3d.com/threads/228844-4-3-Interrupting-a-transition-when-animating-material-color-with-Mecanim
     
  3. Alf203

    Alf203

    Joined:
    Dec 7, 2012
    Posts:
    461
    Ok making some advancement and I actually think its not possible…

    So apparently there is some type of rank system, but its not clear what it really does. From what I understand this seems to work when you have more than one transition going to the "same" state which doesn't make sense….

    Will try to find out more...
     
  4. Oconim

    Oconim

    Joined:
    Feb 6, 2014
    Posts:
    3
    Thanks for the heads up. Unfortunately having the state change link to any state causes the transition to trigger every frame and causes the animations to glitch out. For now I have somewhat circumvented the problem by changing the crouch variable from a bool to a float and lerp to 1 when the key is held down and return to 0 when the key is released. This creates a smooth transition that can change between the standing and crouched states and I don't have to wait for any transitions to complete. I don't think this is an end all solution however because I'm concerned about scaling. Working with nested blend trees is a rigid process and I can't really copy and paste and move them around the whole animation controller in case I need to change or rearrange things.

    $mecanim.png
     
  5. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,620
    I think it's when you have multiple transitions coming from the same state, which does make sense.
     
  6. Alf203

    Alf203

    Joined:
    Dec 7, 2012
    Posts:
    461
    Please correct me if I am wrong but the way I understand it, is that you can only cancel a transition with another that is in the same direction (both "coming from" the same state if you prefer). When I said it didn't make sense its because it wasn't suited to solving the current problem at all, so sorry for expressing myself poorly.

    Anyways as mentioned above, I'm looking to being able to cancel and reverse a transition without it reaching the state it was going to. The float trick works for a blend tree but otherwise its just a hack. Please share if you know a real solution is possible.
     
    Last edited: Mar 3, 2014
  7. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,620
    Oh, I was just clarifying how the ranking for interruption works, in that the transitions that can potentially interrupt a current transition are others from the source state, as opposed others leading to the destination state (from potentially arbitrary other states).

    But for what it's worth, it could potentially make sense to have multiple transitions that share both start and end states. For instance, slow and fast transitions that are triggered by different user input would make sense that way.
     
  8. Alf203

    Alf203

    Joined:
    Dec 7, 2012
    Posts:
    461
    I hear you, thanks for the clarification !

    Its just too bad there is no way to cancel and reverse a transition.

    Heres a use case which would be common :

    I have a UI panel that scales up when the player presses pause and scale downs when he cancels. If I used Mecanim to animate it, even if the player would hit cancel right when it starts scaling, the menu would only scale down after it would have finished scaling up, making this very unresponsive to the player's input.

    In other words, if I'd press pause and cancel right away it would show the reaction long after I would have pressed the cancel button.
     
  9. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,620
    That's correct, and it's definitely a limitation. However, Mecanim's focus is pretty clearly on character animations, and there are plenty of other awesome tools for the kind of use case you're talking about, so it's not the kind of use case I personally think Mecanim should be focusing on now.

    A use case where the same limitation is an issue, however, would be changing the state of a character's motion - standing to crouching and back. Cancelling a crouch before it's finished would still result in the character going all the way down then all the way up. There may be other ways to work around that, though. (For instance, I don't know how calling CrossFade(...) from script would behave in this regard.)
     
  10. Alf203

    Alf203

    Joined:
    Dec 7, 2012
    Posts:
    461
    That was just an example to show that the system is flawed. To be honest for things like this I have my own system that does it programatically. With the recent addition letting you animate material properties in shader from mecanim, one can wonder. What's the point of adding this half finished feature if I can already do it fully with scripting. The answer is that it is for the artists that need to do it visually.

    And with the upcoming new Gui they won't have a choice to focus on this aspect, because how do you think artists will animate the new UI ?

    Since mecanim is to replace the legacy, then it needs to be usable in almost any situation, not only for humans. Mecanim has been moving away from being "just" for character animation.
     
    Last edited: Mar 3, 2014
  11. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,620
    Absolutely. My point was just that, at least in my opinion, while it's still very much a work-in-progress I think it makes a lot of sense to focus on those features that are most aligned with it's strongest unique strength.

    It won't win anyone over by just doing another thing that we already have a multitude of options to get done. It has to either a) save us lots of time somewhere or b) enable us to do things that we couldn't otherwise do.
     
  12. PeytonHanel

    PeytonHanel

    Joined:
    Aug 14, 2014
    Posts:
    7
    Sorry to revive an old thread, but I figure this could help somebody. What worked for me is that I went to my transition and changed the "Interruption source" from none to next.
     
    Cylau and DezBoyle like this.
  13. iceblockwen

    iceblockwen

    Joined:
    Mar 23, 2016
    Posts:
    1
    I did the same thing, but it only works when the state of the transition was added to the state mechine after the state which wants to interrupt the transition.
     
    AnsNovoselov likes this.
  14. DezBoyle

    DezBoyle

    Joined:
    Feb 10, 2013
    Posts:
    5
    This worked perfectly! Thank you!