[SOLVED] How do I simply change the scene skybox in code?

I thought this would work but I just get the error ’ cant read properties of undefined reading ‘scene’:

skyboxAsset = this.app.assets.find('mySkyboxName', 'cubemap');

if (skyboxAsset) {

        skyboxAsset.ready(function () {
            this.app.scene.skybox(skyboxAsset.resource);
    });
this.app.assets.load(skyboxAsset);

Its says it here:

If this.app is undefined, then you are calling it from the wrong context.

BIND

Thanks :slight_smile:

Although I can switch the cubemap now, it doesnt seem to affect lots of objects in the scene. It affects many but I think that lightmapped objects seem to retain the original scene’s skybox. Is there something else I need to do?

Lightmapped objects have ambient light (cubemap or constant) baked in, so they’re not affected by realtime lighting.

Hmm Thanks but Im not sure if that’s actually true if the lightmap material is set to Lighting=true and use Skybox = true. The skybox was certainly doing something weird to the material.

Either way, I fixed this (so the new skybox looks correct) by adding the following line which seems to update the skybox:

this.app.scene.setSkybox(skyboxAsset.resources)

1 Like