How to serialize an Animation component

Hello,

I have a script that goes through a GameObject’s hierarchy, catches its transformation and those from its children during a certain amount of frames, and creates an AnimationClip. This clip is then added to an Animation Component of the GameObject.

When the Editor is in Play mode, I can see that my clip is correctly created and that all my AnimationCurves are filled with keys. But when I stop the Editor, there is no more tracks of the clip and the Animation Component is empty.

I tried different things, without success :
-set my class as [Serializable]
-create a public attribute of type Animation and flag it with [SerializedField]
-add an Animation Component manually before running my script

I googled and looked into the forums, and it appears that there are some plugins that allow for serialization but they do to much things for me. Basically, I just want to do something like MyGameObject.Serialize or MyGameObject.SerializeComponents, so that after running my script, I get my Animation and its clip for the next run.

Thanks for your help.

Hello,

If there is anyone interested in a solution, here it is : Possible to save animations created from script as clip files in the project? - Questions & Answers - Unity Discussions

The key is to serialize the AnimationClip and not the AnimationComponent as I thought.

2 Likes