Accessing clipAnimations from FBX files

Hey folks,

I’m writing a script to process, extract and save animation clips from FBX files - with various settings automatically applied based on file name conventions.

As part of this process, I need to set the AvatarMask. I want to copy the existing ModelImporter.clipAnimations to my own array, set the mask and then write the clipAnimations back to the ModelImporter. The problem is when I copy (or query the length of) the ModelImporter.clipAnimations, I get an empty array back - although there’s clearly clip data in the FBX.

If I ignore the original animations and build a new clip array to add back to the FBX asset, the whole process works fine. My settings are visible and now when I query the ModelImporter.clipAnimations for the same FBX asset, I get an array containing my new clips back (but of course I’ve lost my original animation data).

Previously, I have successfully extracted clips from the FBX by using AssetDatabase.LoadAllAssetRepresentationsAtPath(myFBXfile) - which results in valid AnimationClips - but I can’t set the AvatarMask on these as its part of the importer.

Any suggestions greatly appreciated!

some code to clarify my process (using Unity 4.3)

string assetPath = <my FBX file path>;
ModelImporter mi = AssetImporter.GetAtPath(assetPath) as ModelImporter;
ModelImporterClipAnimation[] anims = mi.clipAnimations;

old thread, but still valid; instead of using clipAnimations (which looks at the list provided by the asset metadata) use defaultClipAnimations (which takes them straight from the fbx)

		ModelImporter MI = (ModelImporter)AssetImporter.GetAtPath(assetPath);
		ModelImporterClipAnimation[] clips = MI.defaultClipAnimations;

Only After user edit clip mannualy and press apply, you can get non empty aniamtionclips array in ModelImporter.

When import animation-fbx firsttime, although you can see a clip"Take 001" in the inspector.

But!! If you open the .meta file, check inside.You’ll find animationclip is empty!!

So I suppose to use external file to record clip’s information(starttime, endtime, name,…), then create new animtionclip by exteral file

right,but i have found a other way to get the aniamtionclips array when import animation-fbx and copy to a new array,this is code:

public class PreImportFBX : AssetPostprocessor
    void OnPostprocessModel(GameObject go)
            Animation anim = go.GetComponent<Animation>();
            AnimationClip[] clips = AnimationUtility.GetAnimationClips(anim);
            List<AnimationClip> clipList=new List<AnimationClips>();
            foreach (AnimationClip clip in clips)
               AnimationClip newClip = new AnimationClip();
               EditorUtility.CopySerialized(sourceClip, newClip);

have a good day!