How to get animation clip start and end times from an imported FBX?

I’ve got an imported FBX file with animation in it. I’ve split that animation into clips. I’m writing an editor script to ensure these clips don’t overlap. However, I can’t seem to find any way of getting the start and end time of an animation clip when it belongs to an FBX. The only thing I can find is a length property.

GameObject gameObject = (GameObject)AssetDatabase.LoadAssetAtPath(assetPath, typeof(GameObject));
foreach (AnimationState state in gameObject.animation) {
    // state.clip...?
}

47647-cliprange.png

I figured out that I can get access to the ModelImporter for the FBX file. From there I can access its clipAnimations array. The ModelImporterClipAnimation objects have .startFrame and .endFrame properties.

ModelImporter modelImporter = (ModelImporter)AssetImporter.GetAtPath(assetPath);
ModelImporterClipAnimation clip = modelImporter.clipAnimations[0]; // get first clip
Debug.Log(clip.startFrame);
Debug.Log(clip.stopFrame);

Note that these are frames, not float time. However, this corresponds to the frame numbers in the FBX inspector. To convert the frames to time, simply multiply by the animationClip.frameRate.

Update (for ~ Unity 5.3) : .startFrame and .stopFrame do not seem to exist anymore. There is a “.firstFrame” and “.lastFrame” which are floats.

I guess there are some fringe cases where you’d want an animation to start inbetween keyframes or something?