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; Debug.Log(anims.Length);