Way to dispose all the assets loaded from a file (GLTF) leaving intact the rest of scene

Hi there:

In my project, I’m using BABYLON.SceneLoader.ImportMeshAsync in order to load several assets (in GLTF format) to build my scene.

This said, I wonder the way to dispose all the assets (mainly meshes, materials, textures and animations) coming with a specific file (GLTF) from the scene, but leaving untouched the rest. It would be a kind of anti-import ( :mask:), you know.

Thanks in advance for your time.

I believe the easiest way which gives the full control is to create an array with the list of imported meshes. When you need to dispose the loaded GLTF just dispose meshes from this list until it will be clear.
Mesh.dispose() has the flag disposeMaterialAndTextures to dispose associated materials and textures when true - Mesh | Babylon.js Documentation
To dispose animations associated with the mesh one needs to go through the array of mesh.animations - Mesh | Babylon.js Documentation

1 Like

Wow, I didn’t know about the disposeMaterialAndTextures flag, great stuff! And of course, It would be nice to have another one named “disposeAnimations”.

Thank you very much for your help, @labris.

1 Like