I can’t figure out how to set animation settings for Mecanim animations in AssetPostProcessor.
On either OnPreprocessModel or OnPostProcessModel, the ModelImporter.clipAnimations does not contain any entries.
During OnPostProcessModel, AnimationUtility.GetAnimationClips does not return anything.
Googling around I found some people using ‘Object.FindObjectsOfType()’. But two issues arise.
it often returns more animations than are being processed currently (to be expected really if you think about it)
If I get the ‘AnimationClipSettings’ from it, it doesn’t actually update the settings as I want them… nor do I know what setting to change to make it ‘Bake Into Pose’.
Here’s what I need really. I want it so that all my models that are imported have their animations set to have all three root transforms (rotation, positionY, positionXZ) to be ‘Bake Into Pose’ and ‘Based Upon Original’.
Of course this is NOT the default import setting, which is really annoying, and I have far too many animations to be constantly doing this by hand for every single animation. But of course, post processing mecanim settings has little to no documentation what so ever.
The only solution I have found is to manually create a ModelImporterClipAnimation[ ], fill it up with data and assign it to clipAnimations. Note that even after model is imported once, you cannot modify clipAnimations elements from an editor script. To get the data you can either use an FBX parser or use the data Unity already parsed in importedTakeInfos variable. importedTakeInfos is a NonPublic Property which can be accessed by Reflection. Credits to AlkisFortuneFish for this nice solution.
Added AssetPostProcessor.OnPreProcessAnimation, this new callback is called just before animation clips are created.
Added ModelImporter.defaultClipAnimations (list of ModelImportClipAnimation based on TakeInfo) and ModelImporter.importedTakeInfos (list of TakeInfo from the file).
Added API for Avatar
BTW you still need to assign avatar rig for every animation manually, I did not found a way around that in Unity 4.x so far.
Here is my Editor script I use with Unity 4.x, customize to your liking…
thanks Zyxil, it works well, only a small problem, every time after postprocess, the gameobject in editor become unapplied and popup a dialog, i have to manual click apply, do you have same issue?