How to destroy and recreate object with animations

How are you?

How do I clean up an animation mixer for an object?

So…

When I launch my THREE.js app, I initialize my ‘World’ with an animation for an object that represents a person.

I have a button that removes the object and recreates the object+animation with randomized position values BUT…

At this point though I have 2 animation mixers because the first one did NOT get cleaned up when the object was “disposed”?

So my question is…

How do I clean up mixers/clips/actions/etc.?

Regards,
Thad Duval

In general, it should be sufficient if you just remove all references to the previous animation mixer so the GC can do its work.

If you want to reuse an existing mixer but just cached resources for root objects, clips and actions, use the uncache*() methods of AnimationMixer. More information in the docs:

https://threejs.org/docs/index.html#api/en/animation/AnimationMixer

How will we remove the reference of the animation mixer object?

I am trying
animationactions[id][0]._mixer.uncacheAction(clip,.object3D(root))
I am getting this error
Cannot set properties of undefined (setting ‘_cacheIndex’ three.js) after playing the animation.