- Home /
Animation Length Mecanim
How would I get the animation length with Mecanim? With legacy it used to be along the lines of animation["myAnimation"].length. But now that doesn't appear to work.
Does anyone know a way to get the length of an animation with the new system?
Thanks.
Answer by DomDom · May 05, 2014 at 02:57 PM
I could solve it via AnimationEvents http://answers.unity3d.com/questions/615041/mecanim-animation-events-1.html So you can react to a specific frame
Answer by EliteMossy · Apr 25, 2013 at 11:28 AM
As far as i am aware, this is not possible atm, and i am not sure when we will get such stuff. The only thing i could find is using GetCurrentAnimatorStateInfo and its .length property, but i am not sure if it is 100% accurate.
Bumping because Unity devs should have fixed this issue long ago. Any real game dev will run into this problem when using $$anonymous$$ecanim so it NEEDS to be addressed ASAP.
I tried this out yesterday and it seems to work. You can also verify the name of the animation and the value it provides compared to what it shown when you preview the animation.
Answer by Felix_Draob · Apr 28, 2020 at 02:28 PM
float value = anim.GetCurrentAnimatorStateInfo(0).length;