- Home /
Mecanim CrossFade transition interruption issue
Imagine that you have a idle state running and you have a run forward state. So, if you press W you trigger a transition from idle to run forward with CrossFade and if you stop pressing W you trigger a transition from run forward to idle.
Here comes the problem, the transition takes X time to complete, if you only push W once the character should stop the transition and come back to the idle state, but Mecanim thinks that he's still in idle because the transition didn't finished to go from one state to the next.
So, how I'm supposed to make a responsive movement system through CrossFade if you can't abort a transition when you desire to?
So, you can't come back to the origin state when you are CrossFading to the next because Mecanim believes that you are still on the origin state when, visually, you are not (you are between the two).
Is this a bug, or a desired behavior? If it's a bug, is this gonna be fixed some time soon? If it's the desired behavior, I'm not supposed to use CrossFade in that way?
Thanks.
EDIT1: This is an example of what I want to achieve -> https://www.youtube.com/watch?v=eXQJvZF6AjY
EDIT2: I'm attaching a clear example of the problem: http://www.mediafire.com/download/35bt1484bjlw3b0/Mecanim_CrossFade_Problem.rar
Press W to trigger an Animator.CrossFade from Idle to Walk Forward, you'll that if you press it only once it will keep walking forward until the transition is finished, so you CAN'T interrupt the transition to come back to the origin state until the transition is ended (Idle in this case).
Also, if you press F you'll triger a manual CrossFade to Idle, and, as you can see it won't work until the Idle to Run Forward transition is ended. This is just to make the problem more clear.
Exit Time parameter and Atomic Checkbox. Both accessible by clicking on the transition arrow in Animator window.
I don't know what that have to do with the problem exposed here?
.Play and .CrossFade were popular with the old system but there are better ways in Animator.
There are better ways to control the Animator system without falling back on Legacy methods; Parameters.
Have you actually looked at the items mentioned in my last comment? Have you actually set up a State-$$anonymous$$achine in Animator?
O$$anonymous$$AY! I just looked at your project. You State-$$anonymous$$achine has NO transitions in it.
Right click a state, click $$anonymous$$ake Transition and click on the next state. You will need transitions To and From your States. When you have done this, refer to my first comment.
It doesn't have transitions because I decided to do it fully through scripting with CrossFade.
I tried to use a State-$$anonymous$$achine but I have the same problem and it's a mess to manage for me. Why to force people to use that if you already had full control through scripting with Legacy?
How can you make a smooth transition but be able to make a transition back to the origin BEFORE the first transition is finished if you need to?
Thanks for the help.
(I'm talking about this: https://www.youtube.com/watch?v=eXQJvZF6AjY)
Answer by PabloJMartinez · Jul 09, 2014 at 03:35 PM
So, the thing is that it seems it's impossible to do this through scripting with CrossFade, ok.
So, the solution is to use Blend Trees so you can control the "transitions" manually through scripting with full control with one or two variables. I have used a 2D Freeform Directional Blend Tree because I need multiple speeds in multiple directions, but you should use whichever fits your problem better.
EDIT: As pointed out by gelu23, it's in fact possible to do this through CrossFade by explicitly setting the normalizedTime to 0.
So... if you want to use a state-machine go for Blend Trees and if you want to use CrossFade use normalizedTime 0.
To do this through scripting you have to set normalizedTime to 0 (or any other value different from float.NegativeInfinity). like: CrossFade(stateName, transitionDuration, -1, 0);
Answer by turdann · Jun 23, 2015 at 12:57 PM
You should mark your transition as "Interruption Source: Next State". This way, the transition could be interrupted by trantisitons of the next state (run forward).
Answer by MartinTV · Jan 06, 2021 at 05:38 AM
Waaaay late to the party here, 8yrs, so might not be relevant BUT I cached the current state (on the 3rd layer), called rebind, then used animator.play to force the character into the animation they were just in with the normalized time value for the cached sate.
void RebindAndRestoreAnimator()
{
// Cache info
Animator anim = PlayerInfo.playerAnim;
AnimatorStateInfo info = anim.GetCurrentAnimatorStateInfo(3);
// Rebind then resetinfo
anim.Rebind();
anim.Play(info.shortNameHash, 3, info.normalizedTime);
}
Your answer
Follow this Question
Related Questions
Mecanim issue: Twitching when blending into blendtrees 1 Answer
Problem with Hash IDs & End of animation detection 2 Answers
Mecanim and Ragdoll Issues? 2 Answers
Problems with Animator(Mecanim) 1 Answer