createDefaultSkybox hides everything on the scene

Hi
I have a scene. It have a few meshes. But the moment I call

    const cubeTextureUrl = this._skyBoxConfig["cubeTextureUrl"];
    if (!cubeTextureUrl) return;
    const texture = new BABYLON.CubeTexture(cubeTextureUrl, this._scene, null, null, null, () => {
      this._scene.render();
    });
    const skybox = this._scene.createDefaultSkybox(
      texture,
      this._skyBoxConfig["pbr"],
      this._skyBoxConfig["scale"],
      this._skyBoxConfig["blur"],
      this._skyBoxConfig["setGlobalEnvTexture"]
    );

and everything is hidden from the scene and I must press on the canvas with the mouse or resize the window for the scene to be redraw.

I have tried adding

() => {
      this._scene.render();
    });

as the final argument of the new BABYLON.CubeTexture but I seem the actual issue is with createDefaultSkybox.

What should I do after I call createDefautlSkybox for the meshes to appear again?

Thanks

Update 1
If I do

    setTimeout(()=> {
      this._scene.getEngine().resize();
      this._scene.render();
    }, 1000)

Then it works. I trigger the resize manually and the element is shown. But I guess there is something else I am missing.

Update 2:
This does not work

    skybox.onAfterRenderObservable.addOnce(()=> {
      this._scene.getEngine().resize();
      this._scene.render();
    })

The skybox still hides everything and the observer is not called event once.

Update 3:
This is what worked. I kind of understand why, but can’t I just call ‘this._scene.render()’

    this._skyboxRenderLoopCounter = 0
    this._skyboxRenderLoop = () => {
      this._skyboxRenderLoopCounter++;
      this._scene.render();
      if(this._skyboxRenderLoop >= 1) {
        this._scene.getEngine().stopRenderLoop(this._skyboxRenderLoop)
      }
    };
    this._scene.getEngine().runRenderLoop(this._skyboxRenderLoop);

Well yeah, you must render the scene to see your change if you are not using a renderloop.

But when I just do this._scene.render() it does not work. I must start a render loop for it which is bugging me.

you should not have too
But also you have to make sure the scene is ready before rendering it so maybe something like:

scene.executeWhenReady(() => scene.render())
2 Likes

Wow. That is something I did not know. I will try it now and look for tutorials on “Scene When Ready”

Thanks

1 Like

Yes. This resolved it. I now know one more method from the API - executeWhenReady. Nothing can stop me now. Mua-ha-ha.

Thanks @Deltakosh

My pleasure :wink: