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...?
}
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.