Hey there,
I am trying to dynamically get the length of an animation that I am playing using Animator,Play(string)
because this gives better overall results visually with sprite animations.
When I call Animator.GetCurrentAnimatorStateInfo(0)
I do not get the currently playing animation, only the information from the Idle animation, even when I play other animations
Any thoughts on how I can get the details of the currently playing animation without hard coding values or names of animations on for details
Animator.Play doesn’t change the current state until the animation system next updates (i.e. next frame). So you need to either wait a frame before checking the current state or use a non-retarded animation system.
1 Like
Thanks, I’m not sure to what you mean by use a non-retarded animation system
Use a different animation system that doesn’t do dumb stuff like force you to wait a frame to get information about something you just told it to play.
Oh okay, Do you have any recommendations for other Animation Systems? Anything in the Assets store for 2D sprites?
I don’t know exactly what info you’re trying to get from the state, but my Animancer plugin (link in my signature) would likely make it extremely easy to achieve what you want. Animancer Lite is free and most of the Pro-Only features aren’t necessary for sprite based animations.
The Legacy Animation system is also a fine choice. I don’t personally like the way it works, but if I hadn’t made Animancer I’d definitely choose Legacy over Animator Controllers for sprite based animations.
Thank you very much, I will take a look at Animancer!
While I don’t entirely disagree with the above poster’s sentiment about mechanim, in this case there is a simple albeit surprisingly poorly documented feature. Simply call the Update() method on your animator to ‘pump’ it thus allowing you to get access to the new state info immediately.
1 Like
Just in case someone isn’t aware, Update() method has a deltaTime parameter and you can simply pass 0 to it.