AnimatorStateInfo.length is infinity.

The ‘length’ field returned from GetCurrentAnimatorStateInfo and GetNextAnimatorStateInfo appears to be infinity. This was working in 5.1.1 and seems to be broken in 5.1.3.

Looks like its known about: Unity Issue Tracker - [Playable] GetCurrentAnimatorStateInfo not working

Awesome. :frowning:
I’ve got a demo to show in a week or so. When’s the patch coming?

Its not fixed yet so don’t hold out for the patch. Can you roll back to 5.1.1?

Shame. No, we can’t roll back unfortunately. I’ll get round the problem another way.

I also got this problem.
It seems to be fixed in Unity 5.2.1 (also working in 5.2.1p4)

But there is some tiny changes in “AnimatorStateInfo.length”
In my game i need to pause my animations. i’m doing that by setting the animator speed to 0. But after that i’ve got AnimatorStateInfo.length returning infinity. I assume that now, the time is inversed scale by the speed.

i managed to get my projet running again by using “AnimatorStateInfo.GetCurrentAnimatorClipInfo(0)[0].clip.length”;
Since i only got 1 clip in my state that was easy.

But if you got a more complicated animation state, you should use the weight info to compute the real time.

This appears to be still broken. Seems to work when requesting layer 0, but not layer 1.
I’m using Unity 5.3.1p3.

May be worth trying the latest version 5.3.4px. If its still not working please file a bug report and post the number here. I’ll make sure it goes to the right person

it expected to get a length of infinity if:

  1. set animator speed to 0.
  2. set animation state speed to 0.
  3. set animation state speed multiplier to 0.
1 Like

Did anyone verify if this is fixed in the latest 5.3.4 patch, or the 5.4 beta? It’s broken in 5.3.2f1.

if it’s broken please log a bug, we are not aware of all issues

Oh I thought it was already known and logged, and fixed in a 5.3.4 patch release. I’ll reproduce it tomorrow morning and log a bug. Thanks.

Sorry to be a scratched record but this is still broken. Couldn’t find an associated bug for it.
It’s not working if the animation is blending.

I never got around to logging a bug - I just worked around it.

Can’t work around this one, I’m afraid. I need to know the length of the anim so I can slow it down/speed it up to match a specific time.
Can’t seem to find an ‘Add new issue’ button on the issue tracker page either. Not my day. :frowning:

Is this a relatively new thing?

Alternatively, is there a way of getting the length of the state before it start’s playing? i.e. once I’ve set the appropriate anim parameters for a blend tree, can I query the length of the clip it’s going to play? I have anims that need speeding up depending on how quickly you attack so I need to set the playback speed parameter to make the anim play over a set time. I was doing this by setting the parameter to 0 (so it didn’t progress past frame 0) and once it’s playing I can set it to match the time. This no longer works.

That normalising behaviour is annoying. Is it actually useful? I just want to know the length regardless of what speed is set to. If the speed is 2 it just means we get to the end quicker but the length should still be the same!

hm, i think the problem can be solved by:

yield return new WaitForEndOfFrame();

After that, this line will return right value:

animTime = GetComponent<Animator>().GetCurrentAnimatorStateInfo(0).length;

If anyone cares )