- Home /
Run-time generated AnimationClips leaking
I currently create AnimationClips dynamically while my game is running to move some pieces around. You can see what I mean here: https://youtu.be/u1My9JX4K-c?t=8s , when the pieces get grouped together and then open again. I cannot reuse the clip because the pieces will have a different position next time, so all the movements need to be changed.
Right now, I create a new clip whenever I need them to be grouped and separated, and attempt to replace any existing clip with this:
private void ReplaceAndPlay(AnimationClip clip, string name) {
var old = Anim.GetClip(name);
if (old != null) {
Anim.RemoveClip(name);
Destroy(old);
}
Anim.AddClip(clip, name);
Anim.Play(name);
}
(Anim just points to the gameObject's Animation component)
But using the profiler, I see that the animation clips just keep accumulating, they don't seem to be garbage collected. Am I missing something or doing something wrong? Can they be garbage collected?
Hmm, that's strange. I never had a case where i needed to constantly creating new clips. However since you properly destroy the old clip it should work i guess. However maybe the RemoveClip method doesn't do it's job correctly and there might be a reference to the "managed corpse" of the old clip somewhere.
Anyways i don't quite get why you can't reuse the old clip. You can call ClearCurves on the old one and add the new curve data.
Your answer
Follow this Question
Related Questions
Can the animation editor create local rotational data? 3 Answers
Adding animation clips via script 2 Answers
Can I make animations snap to a frame? 1 Answer
How to select an animation clip by index number? 7 Answers
How can i start an animation from the position a previous animation was interrupted? 1 Answer