- Home /
Instant transition with Mecanim (Unity 2d)
Hello guys, I`m using mecanim state machine with Unity 2D. I have several 2D elements that is supposed to play in sync (character with different eyes, hair and cloth possibilities). I set my transitions blend to 0 size and tryied with atomic option enabled and disabled (I`m not sure what this could help but I saw something about this here)
Im not using ExitTime because I want the transition occurs in the exactly call from a trigger (the exactly frame). However I
m getting about one frame of difference between my animated sprites (believe me, some parts of the eyes need to move without any delay or something very odd happens)
I put a trivial example below (A one state animator trigged by a boolean called dance).
I set my trigger in a simple code as the one below (Unityscript):
var childAnimators : Component[];
function Start ()
{
childAnimators = GetComponentsInChildren(Animator);
}
function Dance ()
{
for(var littleAnimator:Animator in childAnimators)
littleAnimator.SetTrigger("Dance");
}
I think I have the same problem :(
Somehow Unity always resets the instant transitions to like 50% if the current animation.
I dont know why that is teh case. $$anonymous$$aybe its a Bug or it's intended. Searching the web didn't give any clues...
So an instant switch of the Animations in the first frame is not possible?...
Have same problem - no instant transition. And changes to the ti$$anonymous$$gs in the transition window don't stay - always revert to like 50%....
Answer by Clopay · Jan 15, 2014 at 06:57 PM
For animation transitions, I've had a bit better luck with scripting (C#); however, while scripting the animation made an improvement with the animation transition issues, it brought a new set of challenges for me.
I've got a sprite sheet from which I derive multiple animations. So far each animation is only 2 frames. I have each frame last 0.5 seconds for an animation lasting one total second. My problem in using the animator controller was instantaneous transitioning (or lack thereof) from one sprite animation to the next. If I'm walking and I jump, if I'm falling and I land, or some other transition, it needs to play out the entire frame before it transitions. That's a minimum of a 0.5 second lag. The different features in the transition property don't seem to do much - I have not seen a change yet whether "Atomic" is checked or not. Perhaps I'm not using it right?
The "Any State" animation box is very useful, but is limited as far as player states. Transitioning from "Any State" to another state allows your animation to transition immediately; the problem arises when you need to transition from one state to another - neither of which are "Any State."
I have tried scripting it. The scripting seemed to work a bit better - when I went from idling to walking, the walking animation would cut off the idling animation as expected, and so on. This was pretty easily done - I simply added an Animation.Play("Idle")
in the code. That's it. But eventually my code became so chaotic and buggy that I had to reduce it, and that meant cutting the animation out.
I have yet to dive into Unity further, but these are my experience so far. Everything is working amazingly and is far better than having to write out an entire script dedicated to animating your sprite sheet. I just wish I could figure out how to transition instantly in the animator!
Hopefully one of my attempts can enlighten you as to working towatds a solution!
-Clopay
Answer by Shifty-Geezer · Jan 17, 2015 at 08:15 PM
Just found if I use an exit time of 0.01 instead of 0.00, it instantly transitions. An exit time equal to zero is possible a special case to use the full length of the (longest?) clip.
Answer by MJonee · Nov 01, 2014 at 01:35 AM
I'm using triggers to change animations, but also using exit time with 0.0. If I used only triggers, then the time reseted to 50%. Using exit time with 0.0 fixed it.