Get AnimationClip Looptime [Solved]

Hello,

I would like to know if an animationClip is set to loop. I’m having an Animator and is looking for the loopTime of each AnimationClip.

After few try, I learned that:

  • wrapMode isn’t what I’m looking for; the loop come from the clips loopTime and the wrapMode is set to Default to use it
  • from the documentation the only variable from which I can access loopTime is ModelImporterClipAnimation.loopTime
  • After looking on stackoverflow and from the documentation It look like to get a ModelImporterClipAnimation I need to import the fbx as a ModelImporter using the AssetImporter. But the animation clips come from clips that are in an animation controller and not in a fbx files but directly .anim files (It may look dumb, but I’ve tried to import the animator and cast it to ModelImporter but as expected it’s not possible).

Can someone help me to know if an animation clip is set to loop in editor mode?

May the gods have pity of my soul. I just need the LoopTime of a clip :frowning:

After some digging, AnimationClips use AnimationClipSettings which lead me to AnimationUtility.GetAnimationClipSettings()

Oddly enough there seems to be no documentation of this. It is Editor only API.

2 Likes

Hi,

Have you tried wrapMode?

Thanks, for yours answers!

@arfish Yes, sadly the wrapMode is a value that we can set to override the animation loopTime but since my information about looping was directly on the animationClip, the wrapMode was just set to Default.

@MaskedMouse It’s working pretty well! To be honest I saw it while looking for an answer but since I wasn’t able to find GetAnimationClipSettings in the documentation of AnimationUtility I came to the conclusion that it was outdated without event giving it a chance. But I’ve tried it and it is working like a charm.

@MaskedMouse yes I confirm this is working well:

AnimationClipSettings myClipSettings =  AnimationUtility.GetAnimationClipSettings(myClip);
myClipSettings.loopTime = true;
AnimationUtility.SetAnimationClipSettings( myClip, myClipSettings);
1 Like