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:

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


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:

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, 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:

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


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?

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.

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