Benefit of Using Scenes?

Obviously this is a big-picture question, but I was wondering the utility of using multiple scenes in BabylonJS, as opposed to storing multiple environments in one scene. So far, in my project I have a few distinct environments that each belong to their own distinct scene, but I’ve been going over a code refactor and weirdly enough - on the programming end I feel like it might be easier/cleaner for me to store all of the environments I need in one single scene.

I could do this in a few ways. I could hide all of the meshes and disable the functionality of all environments excluding the one the user is currently in. I could also have each environment set up very distant from each other (1000s of units away, for example), so a user couldn’t see one environment when in another, despite them still existing in the same scene.

Outside of structure of the code itself, I was wondering the disadvantages of doing things like this? I’m still a novice when it comes to BabylonJS and 3D on the Web in general, so there might be a glaring issue I’m not seeing. I’m also concerned if doing this might have some type of effect on performance, specifically if I don’t implement it correctly? Would invisible meshes in a scene still cause extra processing?

1 Like

@Steven_Shoes I don’t have a definitive answer for you, but I’ve wondered the same thing myself. What’s the advantage or use case for multiple scenes?

Until now I’ve also just used the one scene for everything, although I do intend to use AssetContainer.addAllToScene() and AssetContainer.removeAllFromScene() to handle it more elegantly.

1 Like

It will last until all your environments will be too much for a single scene :slight_smile:
(Of course, it depends on an application).

If your design allows for multiple scenes then it can be better than having everything in a single scene because even if some objects are invisible/disabled, they are still in the list of all meshes and are scanned through each frame. If you know a scene is not visible you can simply not call render for it and avoid the whole processing.


Yes, but if you are really aggressive, you might already be using that mechanism inside a scene. Here are 2 old screenshots I made for another topic:


To implement tabs, I instance, parent, & layout all the meshes of each tab. The stuff off a tab that is not the active one is disabled. It can start to get really tricky to use one mechanism for multiple things, and makes for brittle code.