[SOLVED] How do I switch scenes with code?

Anyone can help me?When I change the scenes,There are various problems in the conversion scenario
It will show two scene overlays, and the console reports various errors

This is my project

I just want to implement the function of scene switching. I didn’t expect to have so many problems. I am operating according to the official case.

I believe @halvves is working on improving the documentation on this. I’m sure he can provide some more details around timelines for this.

What should I do now?:slight_smile:

Have you looked at this project:


From a guess, when the hotspot is destroyed through changing scenes, the callbacks from mouse input haven’t been removed so you have a ‘dangling’ callback.

If you look at the model viewer starter project, you can see that it removes the callbacks when it is destroyed: https://playcanvas.com/editor/code/446385?tabs=6079417

I am sure that I am using the code of this scene to change it. If the scene is very simple, it will work. If the scene is complicated, for example, my project will have serious problems.

How do you change scene in the app?

:joy:What’s that mean?

I use this part of code to change my scene…this part of code from the official example

I can’t reproduce the issue you are having as I can’t seem to be able to change scene when playing the app. What hotspot do I click on? What button do I press?

Launch the ‘360InTheCar’ scene by Click button to change the scene.:slight_smile:

Do you have any products for sale? I want to buy some of your products to thank you, I hope the official forum can give a reward function to thank the enthusiastic netizens.

By adding the code to remove the event callbacks when the hotspots are destroyed fixes the error that the console brings up:

Fixed version:

The other problem about the two ‘overlays’ isn’t really overlaying. When loading and destroying scene hierarchies, it doesn’t change the skybox. You will have to load/unload that in code.

Sorry I am late to the party. It looks like @yaustar has already covered the main issue with removing event listeners on ‘destroy’ of the entity, and it seems he already has recommended the remaining fix of handling loading/unloading your new skybox when swapping scenes.

I will try to highlight these issues in an update to the scene switching tutorial and docs soon!

Thx,Looking forward to your new tutorial:)