Search Unity

animator.GetCurrentAnimatorStateInfo(0).normalizedTime == -infinity

Discussion in 'Animation' started by douglassophies, Jun 5, 2020.

  1. douglassophies

    douglassophies

    Joined:
    Jun 17, 2012
    Posts:
    141
    This:
    Code (CSharp):
    1. animator.GetCurrentAnimatorStateInfo(0).normalizedTime
    returns a value of -infinity.

    I was trying to do:
    Code (CSharp):
    1.  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.
     
  2. dandeentremont

    dandeentremont

    Joined:
    Jan 11, 2013
    Posts:
    24
    douglassophies likes this.
  3. douglassophies

    douglassophies

    Joined:
    Jun 17, 2012
    Posts:
    141
    Thanks @dandeentremont ! That helped me realise the issue is down to this line of code:
    Code (CSharp):
    1. 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:
    Code (CSharp):
    1. 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.