Problem when switching between Scenes

Hello I’m very new to Play Canvas development.

I am currently developing a game (which I can’t share any link to, cause it is a product for the company I work at), which has different Levels. Now we thought, we’d create a Level-Selection as one scene and each level as different scenes with their own scripts etc.

Now I followed the tutorial on how to change scenes from the offical Web-site. Switching from the Level-Selection to one of the levels works fine. Now I have a home button, which takes me back to the Level-Selection and if I re-select the same level I’ve loaded before, all hell breaks loose. None of the variables are correct, I get duplicate entities being drawn etc. I read stuff out of a JSON which doesn’t work either.

I thought that the scene switching as done in the tutorial will load the scene, call the initialize functions and destroy the old hirarchy. Is that correct? Then why do I get such a different result when I change back to a level, when everything should be done the same ? When switching back to the Level-Selection, everything works fine, but when I re-enter a level it just completly breaks it.

Any suggestions ?


I fixed the problem by destroying the old hirarchy first and then load the new one… Had some error, but was able to fix them. Also it’s worth nothing, that any events you bind on"eventName")

will be bound again and if you fire events then they are executed double, thrice etc. So be careful with these when changing scenes and make sure to use"eventName")

Yes, PlayCanvas doesn’t automatically unsubscribe events when an object is destroyed so you do have to remember to unsubscribe.

In PlayCanvas, it doesn’t really have a concept of ‘switching’ scenes. All the scene loads are additive.

1 Like