Hello,
i have the follow script to get the clip duration:
public static float GetClipDuratin(this Animator animator, int clipHash)
{
foreach (AnimationClip clip in animator.runtimeAnimatorController.animationClips)
{
AnimatorControllerLayer layer = (animator.runtimeAnimatorController as AnimatorController).layers[0];
foreach (ChildAnimatorState state in layer.stateMachine.states)
{
if (Animator.StringToHash(clip.name) == clipHash)
return clip.length / state.state.speed;
}
}
throw new Exception($"There is not clip with Hash: {clipHash} in the animator {animator.name}");
}
I’m having an issue where my code only works in the Unity Editor because it relies on UnityEditor.Animations. I’m using this since I often change the speed of states in the Animator, and it’s the only method I’ve found to get the real-time clip duration. Is there another way to retrieve the clip duration if I change the speed in the Animator state?