Reverse effects of createDefaultSkybox


I’m creating a react component where I should be able to define a skybox and clean up once the component is removed (componentWillUnmount).

So basically I try to add a skybox and later remove it. However once I use createDefaultSkybox on the scene, some textures are being added I suppose and I’m not sure how to do proper “clean up”:

 // create
  public createSkybox(pathToEnvTexture: string) {
    const { worldRadius } = utils.getWorldMeasurements(this.scene);
    const envTexture = new CubeTexture(pathToEnvTexture, this.scene);
    this.skybox = this.scene.createDefaultSkybox(
      worldRadius * 30

 // clean up
public removeSkybox() {
    if (this.skybox) {
      this.skybox = null;

Here is an image without skybox -> with skybox -> after removing skybox:

It’s probably because createDefaultSkybox will also create the scene environmentTexture as well.

Setting setGlobalEnvTexture to false should be enough.

Or you can also, in you removeSkybox, set scene.environmentTexture = null

1 Like

Yeah, that solves it!

Though, perhaps I should first dispose it? like:

scene.environmentTexture = null;

It looks like environmentTexture.dispose() give us an error.

But instead of use createDefaultSkybox, I think you should create manually your custom skybox, it will be simpler.

The createDefaultSkybox just create a simple cube using a cubetexture in its reflection texture :

environmentTexture.dispose() seems to work in my case :slight_smile: but if this fails in future I will probably create skybox manually.

I just remade a test, don’t know why I get this yesterday.