AssetContainer.dispose() does not work?

When I try to dispose of an asset container, I get the error this.environmentTexture.dispose is not a function.

Here the example:
https://www.babylonjs-playground.com/#5NFRVE#20

The idea is that I want to import the assets of my level in an asset container, add them to the scene, then, when the level is complete, I would put them back in the container and dispose of them.

Definitely a bug! I will fix it for next commit
Thanks!

the dispose function now workds :slight_smile:
However, I don’t really understand what is the KeepAssets for?

In the PG below, I was expecting to keep the light, ground and camera in my scene:
https://www.babylonjs-playground.com/#5NFRVE#22

Basically, I would like to remove from my scene only the assets that are specific to the current game level (e.g. 3D tiles, etc…) while keeping in memory the assets that are non-specific to the game level (e.g. menu sounds). I thought KeepAssets would help me keeping some assets… am I wrong?

Pinging @trevordev who creates the assetContainer

My bad, I got confused with container.XXXX.push(). I was pushing everything using container.camera.push(), so it did not work from meshes, etc.

Ok, so now, I’ve understood the use of KeepAssets and AssetContainer, I tried with BABYLON.GUI, and it does not seem to remove the GUI from the scene:
https://www.babylonjs-playground.com/#5NFRVE#24

Isn’t it the GUI part of the scene?

@Nodragem, thanks for pointing this out. I’ll try to add gui layers to assetContainer.

1 Like

Hello,

Sorry to be annoying you again, but is that normal that when I dispose of the container, the objects of the scene also get disposed?
https://www.babylonjs-playground.com/#5NFRVE#25

I was hoping to use the asset container to dispose easily of my level assets, while keeping the assets that are re-used between levels in the scene.

@Nodragem no worries, finding issues is very helpful :slight_smile:

Yea the asset container should be able to be used that way, it seems the issue in your playground is that you are keeping the meshes but not the gemetry for the meshes. If you also add the sphere geometry it should work. https://www.babylonjs-playground.com/#5NFRVE#27

I agree this is pretty not obvious I can update the docs to try to reflect this. Similar issues can happen around this if you give the sphere a custom material and don’t also keep that material.

1 Like