Skybox Issues when Loading scene In game

Greetings, i have a slight problem… im doing testing for different worlds in trigo run… which use different scenes… the problem is each scene has a different skybox… and when i load a scene in game… instead of changing the skybox to the new one… it keeps the old one without it changing :confused:

here’s the link to my project if you would like to see my scene loader
https://playcanvas.com/editor/scene/1324849

Hi @Kevin_Herod,

I have run into this issue before. You will want to make sure that you are loading an individual scene’s settings whenever you change scenes. As an example, you can check out my Scene Manager project:

https://playcanvas.com/project/756176/overview/scene-manager

Specifically, in the sceneManager.js file you will find this function:

Notice how it calls app.scenes.loadSceneSettings() while passing the desired scene object on line 93? This is what allows the manager to change the skybox and any additional relevant scene settings while swapping scenes.

I hope this is helpful.

2 Likes

still didn’t seem to work very well here’s my project
https://playcanvas.com/editor/scene/1324849

Hi @Kevin_Herod,

I see you added my script to your project. I’m glad you’re trying to make it work. If you want to use it, it will be important to understand how the script actually works, otherwise it will just lead to frustration when you just copy and paste.

If you take a look at the example project, you will see that there are a total of 4 scenes in the editor, while there are only three that are actually visible to the user that plays the project. This is because the Scene Manager transports itself between scenes, and relies on the events that are passed to it in order to swap between the desired scenes.

The manager (as it’s currently written) expects that it will be added to a scene all on its own called ‘Init’ and that it will load the first scene after that based on the string you provide it.

After that, it will rely on the app level event ‘changeScene’ in order to actually manage the scenes for you. This means that once you have set up the Scene Manager the same way it is on the example project, you will want to change your ChangeSceneOnButtonClick script to look something like this:

var ChangeSceneOnButtonClick = pc.createScript('changeSceneOnButtonClick');
ChangeSceneOnButtonClick.attributes.add('sceneName', {type: 'string'});

// initialize code called once per entity
ChangeSceneOnButtonClick.prototype.initialize = function() {
    this.entity.button.once('click', function() {
//        loadScene(this.sceneName, { hierarchy: true });
          this.app.fire('changeScene', this.sceneName);
    }, this);
};

// swap method called for script hot-reloading
// inherit your script state here
// ChangeSceneOnClick.prototype.swap = function(old) { };

// to learn more about script anatomy, please read:
// https://developer.playcanvas.com/en/user-manual/scripting/

The reason I would make that change is because you’re still calling your original function to change the scene which does not use the Scene Manager’s workflow to swap things out for you.

Of course, there might be other issues you might run into if you try to adjust your project to use the Scene Manager, but we won’t know what those are until these initial setup steps are completed.

I hope this is helpful.

2 Likes

In change-scene-on-click from

// initialize code called once per entity
ChangeSceneOnButtonClick.prototype.initialize = function() {
    this.entity.button.once('click', function() {
        loadScene(this.sceneName, { hierarchy: true });
    }, this);
};

To

// initialize code called once per entity
ChangeSceneOnButtonClick.prototype.initialize = function() {
    this.entity.button.once('click', function() {
        loadScene(this.sceneName, { hierarchy: true, settings: true });
    }, this);
};

Documentation: Loading Scenes | Learn PlayCanvas

We are looking to make this simpler by adding a function to the engine that is currently go through review: Added changeScene API by yaustar · Pull Request #4626 · playcanvas/engine · GitHub