- Home /
Access MecAnim animation clips in a AssetPostprocessor
With the legacy animation system, one used to be able to implement a subclass of AssetPostprocessor and in the OnPostProcessModel function do something like:
public void OnPostprocessModel(GameObject rootObj)
{
AnimationClip[] clips = AnimationUtility.GetAnimationClips(rootObj);
// do something with clips...
}
We're using this to do some processing on our character animations. We'd like to do the same for MecAnim but this function returns an empty array. Is this still possible with MecAnim and, if so, how?
Answer by JensRestemeier · Mar 16, 2014 at 04:16 PM
I found that you can get these AnimationClips with Object.FindObjectsOfType (typeof(AnimationClip))
. In a test with the legacy system this seems to return the same objects as AnimationUtility.GetAnimationClips(rootObj)
, though it includes a few additional animation clips used for the editor. In my case I was able to pick the clips I was interested in by name.
Does this work during the OnPostprocess$$anonymous$$odel phase during import? It's a good suggestion--although a horrible work-around!
Aparently yes. The code I'm using at the moment is
List<AnimationClip> animationClipList = new List<AnimationClip>(AnimationUtility.GetAnimationClips(g));
if (animationClipList.Count == 0) {
AnimationClip[] objectList = UnityEngine.Object.FindObjectsOfType (typeof(AnimationClip)) as AnimationClip[];
animationClipList.AddRange(objectList);
}
... to make sure it'll work if AnimationUtility.GetAnimationClips gets fixed.