I have been goofing around with Babylon for the past 2 weeks and having fun putting together a game.
It’s been a great learning experience and the interactive playground is fantastic.
So I wanted to have a way to load an animated gltf/glb character models and to spawn a bunch of copies as needed. (Enemies, other players, etc.) Most of the examples unfortunately only showed how to instantiate some in the initial callback but I need more flexibility to create them on demand.
I found instantiateModelsToScene() which seems to do a fine job.
So next I found scene.debugLayer.show();
But I noticed when I dispose of the instances, they leave all kinds of stuff in memory.
Textures, Skeletons, Animation Groups, etc.
If I keep adding and deleting they just keep accumulating.
So I figured I must be doing something wrong.
These resources are duplicates that get made during the instantiate.
I found a way (dirty hack) to manually dispose of the copied resources.
I keep an array of the instances/copies and loop over all of the animationGroups, rootNodes and skeletons and dispose them individually.
It works fine in the playground version 4.2 although in 5.0.0 there is a texture that gets skipped and continues to accumulate as you keep adding/deleting more. Maybe a bug?
That’s because this mesh has morph targets: in 5.0, by default the morph target manager uses a texture to store the targets. So, you will need to dispose the morph target managers of the meshes to get rid of the accumulating textures.