Disable scene

Hi, All

Maybe there is some possibility to make flow for switching between scenes without destroying it?
I mean just preload all the scenes when the game is started and then just enable the scene which you need and disable others in order to don’t spent time to destroy and preload next scene when you switch between it. Keep all scenes in memory.


Hi @koroldev,

Yes, that’s definitely possible you can load scenes additively, that is load a second scene without destroying the existing one. Check this example:


Now, scenes are just entities hierarchies. To avoid the cost of adding and initializing the hierarchy on runtime, you can definitely load all scenes in advance and keep their parent entity disabled.

You only enable it when it’s required as a regular entity.


Thanks for your reply, Leonidas.
I am not sure that understand how to turn between preloaded scenes in right way.
Let’s say I have preloaded scene’s root entities, mainMenuRootEntity and gameplayRootEntity
From the start mainMenuRootEntity is enabled and current active scene is mainMenu,
So I want to switch to gameplay scene and I write something like this:

mainMenuRootEntity.enabled = false
gameplayRootEntity.enabled = true

But how I can switch exactly active scene in app? because app.scene is still mainMenu

I see, to do that you need to load the new scene and destroy the previous one.

Check this example: Changing Scenes | Learn PlayCanvas

1 Like

@Leonidas Yea, Thanks, I’ve checked it and it looks like it is what I needed.
Only one weird thing I’ve noticed: I have some shader attached to my gameplay scene, and there is no this shader for mainMenu scene. But when I switch from the gameplay scene back to the mainMenu the shader effect influence on mainMenu objects. So I assume need to clear in some way shaders which was attached to a scene?

1 Like

Oh, I found the answer. Need just to add on destroy listener to the shader and remove all custom chunks from all materials in listener’s callback. Thanks, now all works good!

1 Like