- Home /
Mecanim 1 frame delay [solved]
all animations are facing right, when i change character direction the turn animation faces one way after turn, in the same update i flip change transform:
transform.localScale = new Vector3(1f, 1f,0.001f);
or
transform.localScale = new Vector3(-1f, 1f,0.001f);
i am calling flip and new animation on the same frame / update and i can see one frame glitch, where animation is not changed but character is already flipped
what can i do? is there some delay in mecanim?
**EDIT: it was all wrong since beginning, when i changed movement from adding Vector3 every frame to current position to Vector3.Lerp() between start and end the problem dissapeared completely
sorry for bothering and thanks for trying to help
Answer by Griffo · Feb 27, 2014 at 03:05 PM
I use
yield WaitForSeconds(0);
As in
_animator.SetBool( paramName, true );
yield WaitForSeconds(0);
_animator.SetBool( paramName, false );
thanks for your answer, i did not specify, that i call directly
animator.Play(animationClip.Name, 0, 0f);
which (by my opinion) should start immediately and without fading; it's called from Update and I don't use any coroutines in the project
have you tried looking Here
I'm off to work now so won't be online for hours .. :(
if flip and new animation are called one after the other you shouldn't be see a one frame glitch.
I understand how it should work, it just don't :D I must be doing something wrong, here's the code:
public virtual IEnumerator PlayAnimation(StateInfo animationClip, float duration = float.NegativeInfinity)
{
yield return new WaitForEndOfFrame();
debugAnimationClipName = animationClip.Name;
if (duration > 0)
{
animator.speed = ((animationClip.Length*60f - 1f)/60f)/duration;
}
else
{
animator.speed = 1f;
}
animator.Play(animationClip.Name, 0, 0f);
if (isFacingRight && transform.localScale.x < 0f)
{
FaceRight();
}
else if (!isFacingRight && transform.localScale.x > 0f)
{
FaceLeft();
}
// return null;
}
if I comment the yield line and uncomment the return line, than it works as before (sometimes glitch)
Answer by funshark · May 20, 2014 at 06:33 PM
I have no answer but the same problem currently. Every transition in mecanim have a 1 frame delay
frame 1 : the parameter is checked
frame 2 : the state is activated
frame 3 : the animation in the state is played
( so it's 2 frames in reality )
I'm curious how everyone is dealing with that since it has a big impact on how well the game responding to your inputs :/
dunno if you problem is same as $$anonymous$$e, but in my case it was wrong movement, the mecanim was ok, i had error eslewhere, when i changed movement from incremental Vector3 to Lerp all went fine
Your answer
Follow this Question
Related Questions
Mecanim, start blend immediately? 0 Answers
Resetting a combo chain 1 Answer
How to update 3D character 1 Answer
Cant get rid of animation delay in Mecanim 2 Answers
Weird delay on Tween 1 Answer