- Home /
How to make a instant transition with Mecanim?
Hi, i have animations made one by one, with legacy i just need to call Play the animation states one by one. But with Mecanim, the transition always take time, how do i can make instant transition to switch animation clips?(I mean i don't need blending with some animations)
Thanks!
Answer by Cygon4 · Nov 28, 2012 at 12:50 PM
Current Mecanim Version (Unity 4.3 and later)
You can simply use the Animator.Play() method in your scripts.
This method will instantly transition the animator into a different state, ignoring any blending or transitions you've set up.
The only drawback is that you need to specify the name of the target state in your scripts, so anyone working on the Mecanim animation state machine will have to be careful to also update the scripts when a state is renamed.
Early Mecanim Versions (before Unity 4.3)
In your Mecanim "Animator" (the thing where you design the animation state machine in), click on a transition between two states. The inspector will show you a panel in which you can tweak how the animations are blended together:
If you reduce the blending time to zero there, the animation will switch instantaneously. In my example above, that would mean moving the "Walk" animation all the way to the left and shrinking grey area behind the "Stand" animation (the blending phase) to a length of 0.
Thank you very much, i'v tested this way, mostly it will take 2 frames time to switched to "Walk", but sometimes it will only take 1 frame time which i really want. I can not understand way it mostly take 2 frames, both my render&physics FPS is set to 50.
Uncheck "atomic" to make it so an animation can transition out at any time (and will ignore exit time if there is one).
Using Unity 5.0.0f4 and there is no atomic checkbox; have reduced transition time to zero but still have the same issue. Anyone know an equivalent way to do this in Unity 5.0.0f4?
Untick "Has Exit Time"
Edit: In fact, here's more info. I needed to do exactly what you wanted. Easiest way is to unfold the "settings", set everything to zero, then untick "Has exit time".
Yeah, but what if you want the specific state to have a blending time, and only once in a while you need it to start immediately? Say you have a long transition/blend time, but your fading out the screen and when the screen fades in you want the other animation to be playing without any blending. Is there a way to stop/force finish the current animation state and play the next?
Answer by aniv · Feb 23, 2014 at 09:10 PM
There is a trick if you don't like sliders. Go to the top right corner of the Inspector window and select Debug from the drop down menu (next to the lock). Now you can type in values.
This is a great trick. Just make the Transition Duration 0 and uncheck atomic on every transition. It worked perfectly for me.
This solution doesn't work perfectly, it still triggers 1 or 2 frames from the next animation (which is triggering events to fire twice for me). I really wish Unity would get this fixed ASAP (driving me insane).
If you want to see the 1 or 2 frame bug get fixed vote on the issue here http://feedback.unity3d.com/suggestions/instant-animation-state-transition
I hate sliders. Thank you for this info, it saved me a world of hurt.
Answer by MrG · Feb 02, 2015 at 10:53 PM
Does this not work for you?
Animator anim = GetComponent();
if(Input.GetKeyUp(KeyCode.W)) anim.CrossFade("WalkUp", 0f)
else if(Input.GetKey(KeyCode.S)) anim.CrossFade("WalkDown", 0f);
Manual: http://docs.unity3d.com/ScriptReference/Animator.CrossFade.html
This should bypass transitions. I'm not sure if the current state and the one you specify for the CrossFade have to be connected through an AnyState, so you'll have to try it and see. If not, I'd think you could have your "instant-on" states just orphaned in your Animator and just invoke them from script. Note that the state name is CaseSensitive.
Hope that helps.
Answer by honigkuchen · Nov 27, 2013 at 01:22 PM
I've read so many posts about this. Maybe they come up with an "Instant Transition" Option in the next Unity. Would be much, much, much better than fiddeling around with the sliders all the time...
Answer by YJack · Sep 23, 2013 at 05:04 AM
Same problem here. However, I`m still with a little delay between animations.
Your answer
![](https://koobas.hobune.stream/wayback/20220613084628im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Mecanim transitions sometimes don't work 4 Answers
Copy/Paste Mecanim Transitions 6 Answers
mecanim trasitions auto reset 0 Answers
Mecanim - How to use "Exit Time" for a state that uses negative speed (anim playing backwards)? 2 Answers
Why do legacy & humanoid animations look different on the same character? 1 Answer