I am trying to access an FBX and extract the Animation Clips from it. I am currently doing that like this:
ModelImporter modelImporter = AssetImporter.GetAtPath(assetPath) as ModelImporter;
if (modelImporter == null)
{
Debug.LogError("Failed to get ModelImporter for the FBX Object!");
return animationClips;
}
ModelImporterClipAnimation[] clipAnimations = modelImporter.defaultClipAnimations;
I need to convert these clips to AnimationClips. How can i do this? I can’t seem to typecast.
1 Answer
1
Thanks for reaching out!
The ModelImporterClipAnimation objects are not containing the animation data proper. They are importer settings that capture how users decide to import their animations. In the following picture, I decided to split the incoming animation in two clips (Animation tab on the importer):
In order to retrieve the animation data, you need to load the asset and extract the animation clip. Here is a simple script that lists all the AnimationClips for the the same asset:
var allAssets = AssetDatabase.LoadAllAssetsAtPath("Assets/CubeWithAnimation.fbx");
foreach (var asset in allAssets)
{
if (asset is AnimationClip)
Debug.Log(asset.name);
}
Give it a try, and let us know how it goes!
This seems to have worked, thank you! I created a script that extracted a clip if it found that it was an animation clip, but it seems to have created duplicate animation clips with the preview prefix strangely. I can deal with that, though. Thanks again!
– shebbgames