• Runtimes
  • Unity: how to get the duration of an animation?

Hi, sorry if this is a stupid question but I didn't find any results when googling. In Unity, how do I dynamically detect what the duration of a given Spine animation is? I need the number to feed into a coroutine.

Related Discussions
...
  • Изменено

Animation.Duration

OK well I tried that and it didn't work, although I may have been using it in the wrong context. Anyway, in the end I figured out a way to get what I wanted:

float time = GameObject.Find("animation").GetComponent<SkeletonAnimation>().skeletonDataAsset.GetSkeletonData(true).animations[0].duration;

In hindsight that must have been what you meant ("Animation" referring to getting the animation in the list), but at the time I didn't really know what context you meant it in - finding the animation was the part I was having trouble with. Either way, it all worked out, so thanks all the same!

You can use FindAnimation on SkeletonData to find an animation by name.

Excellent, that makes things easier. Thanks!