This:
animator.GetCurrentAnimatorStateInfo(0).normalizedTime
returns a value of -infinity.
I was trying to do:
if (animator.GetCurrentAnimatorStateInfo(0).normalizedTime > 1)
to test if an animation has finished playing but it only works for a little while before the -infinity value pops up.
What might cause this?
The below values are all set to 1 when i get the -infinity value:
animator.speed
GetCurrentAnimatorStateInfo(0).speedMultiplier
GetCurrentAnimatorStateInfo(0).speed
Background:
I have a bool “isAnimationLocked”. This lock is used globally to check if a new animation can be played or if its still in the middle of the current one. I turn it off in Update() if the current animation is done using the faulty code.
animator.normalizedTime is set to negative infinity by default for some reason:
If you’re using animator.Play(), set it explicitly to zero.
Also watch out for it if you use CrossFade() with a hash state (but with a string, it’s initialized as zero!):
1 Like
Thanks @dandeentremont ! That helped me realise the issue is down to this line of code: animator.Update(float.MinValue);
Its purpose is to get the next states details which otherwise seems to be impossible on the same frame I trigger the next animation. (I need the next state so i can set a speedMultiplier on it and have the animation play at a custom speed)
I thought i could set normalizedTime to 0 as a workaround but its readonly.
I tried:
animator.Play(animator.GetNextAnimatorStateInfo(0).shortNameHash, 0, 0);
to see if i could fix it but that does not seem to work. It might also be that i am conflating two separate issues. I assumed the -infinity was why my animations were freezing but might be unrelated in which case i am probably ok to check for -infinity when ever i read normalizedTime and assume a value of 0.