- Home /
Animation.AddClip() copies the clip?
I just want to confirm if this is Unity, or something I'm doing. I have an object that acts as an animation library and when characters are loaded into the scene they fill out their Animation components by using .AddClip and sourcing from the library. Whenever a clip is added it appears to be duplicated in memory. Is this normal behavior for Unity or am I leaking something somewhere?
Thanks!
Answer by disturbing · Oct 28, 2013 at 03:36 PM
This is a really late reply, but I found the issue!
I have multiple animations and 3 different rigs, so I decided to rename all the animation clips when adding them to the Animation class. (This is using legacy Animation, not Mecanim)
So for instance
Spider_Idle Raptor_Idle
Became just "Idle" in the Animation.
AnimationClip animClip = animationContainer.AnimationClip;
string name = animClip.name.Substring(animClip.name.IndexOf('_') + 1);
animation.AddClip(name , animClip);
If name != anim.Clip.name, you will get duplicated animations in memory, every time you AddClip.
So, the solution that fixed our problem was dynamically renaming the animation clip
AnimationClip animClip = animationContainer.AnimationClip;
animClip.name = animClip.name.Substring(animClip.name.IndexOf('_') + 1);
animation.AddClip(animClip.name, animationContainer.AnimationClip);
Hope this helps anyone with this issue. I'm reporting it as a bug to Unity.
Thanks for this, despite it being 5 years ago this still hasn't been fixed. I assume this is because the legacy animation system is to be eventually replaced by mecanim.
Your answer
Follow this Question
Related Questions
Added animation not Playing 0 Answers
Can the animation editor create local rotational data? 3 Answers
Adding animation clips via script 2 Answers
Not playing whole animation 0 Answers
Game works fine in the editor, but glitching on build 0 Answers