# Simulating multiple scenes

**URL:** <https://forum.babylonjs.com/t/simulating-multiple-scenes/58785>\
**Category:** Questions\
**Created:** [June 2, 2025, 3:39pm UTC](https://forum.babylonjs.com/t/simulating-multiple-scenes/58785 "2025-06-02T15:39:27Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![bvaisman](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bvaisman/32/20835_2.png) [@bvaisman](https://forum.babylonjs.com/u/bvaisman)\
**Post date:** [June 2, 2025, 3:39pm UTC](https://forum.babylonjs.com/t/simulating-multiple-scenes/58785/1 "2025-06-02T15:39:27Z")

</div>

Hi everyone,

I need to simulate multiple scenes but in a single one because I need to save / load my scene (stringify, LoadSceneAsync) and these functions only use a single scene : i can’t use the multiple scenes ([Babylon.js docs](https://doc.babylonjs.com/features/featuresDeepDive/scene/multiScenes/)).

So I need to use multiple cameras, each of them showing only some meshes and hiding others…

But : I’ve read that there are only 4 layers for the cameras ([Babylon.js docs](https://doc.babylonjs.com/features/featuresDeepDive/cameras/layerMasksAndMultiCam/)) and i do not know how many “scenes” i need. So I can’t use the camera layers either.

Does anybody know how to do that ?

Thanks,

Boris

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [June 2, 2025, 4:20pm UTC](https://forum.babylonjs.com/t/simulating-multiple-scenes/58785/2 "2025-06-02T16:20:11Z")

</div>

There is no limitation to layerMask (it is a 32 bits number if you us 0x00000000 format so you have as much as you want :))

---

<div class="post-metadata">

**Author:** ![bvaisman](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bvaisman/32/20835_2.png) [@bvaisman](https://forum.babylonjs.com/u/bvaisman)\
**Post date:** [June 2, 2025, 4:23pm UTC](https://forum.babylonjs.com/t/simulating-multiple-scenes/58785/3 "2025-06-02T16:23:51Z")

</div>

Even for the cameras ?

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [June 2, 2025, 4:35pm UTC](https://forum.babylonjs.com/t/simulating-multiple-scenes/58785/4 "2025-06-02T16:35:47Z")

</div>

Yup, I’m not sure where did you get that feeling but the doc does not state there is a limit

---

<div class="post-metadata">

**Author:** ![bvaisman](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bvaisman/32/20835_2.png) [@bvaisman](https://forum.babylonjs.com/u/bvaisman)\
**Post date:** [June 2, 2025, 4:45pm UTC](https://forum.babylonjs.com/t/simulating-multiple-scenes/58785/5 "2025-06-02T16:45:19Z")

</div>

It is probably because i did not underestand the doc here :

> A `layerMask` is a number assigned to each mesh and camera. It is used at the bit level to indicate whether lights and cameras should shine-upon or show the mesh. The default value, 0x0FFFFFFF, will cause the mesh to be illuminated and shown by any stock light and camera. To determine if a mesh is seen by a camera, a [bitwise AND](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_AND) is performed and the result is compared to zero:

_javascript_

```auto
mesh.layerMask & (camera.layerMask !== 0);

```

> The feature is used primarily when multiple cameras are active at the same time. If you wish to have a mesh that is always visible on the screen and pickable, e.g. a button, you might add a second camera and light to the scene to exclusively show and light it.

> You’ll need the 2nd camera to ONLY see the button. The button should also only be visible once.

> Notice that the default `layerMask` starts with the first 4 bits being 0, or off. If the 2nd camera and button were to both have a `layerMask` with one of the 4 values below, then the 2nd camera would only see the button:

> - 0x10000000
> - 0x20000000
> - 0x40000000
> - 0x80000000

I will read it again. Thanks for your answer.

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [June 2, 2025, 4:54pm UTC](https://forum.babylonjs.com/t/simulating-multiple-scenes/58785/6 "2025-06-02T16:54:21Z")

</div>

Overall the idea is that a camera will render any mesh when `mesh.layerMask & (camera.layerMask !== 0)` is true

so if camera.layerMask = 1 and mesh.layerMask = 1 then it will render 🙂

---

<div class="post-metadata">

**Author:** ![bvaisman](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bvaisman/32/20835_2.png) [@bvaisman](https://forum.babylonjs.com/u/bvaisman)\
**Post date:** [June 4, 2025, 10:07am UTC](https://forum.babylonjs.com/t/simulating-multiple-scenes/58785/7 "2025-06-04T10:07:53Z")

</div>

I’m really struggling with the masks but it’s very interesting. If I understand well, i mean there is a mistake in the docs.

in this page ([Babylon.js docs](https://doc.babylonjs.com/features/featuresDeepDive/cameras/layerMasksAndMultiCam/)) it’s written :

> mesh.layerMask & (camera.layerMask !== 0);

And in this page ([Babylon.js docs](https://doc.babylonjs.com/features/featuresDeepDive/scene/layermask/)), it’s written :

> So, for eg, if `camera.layerMask = 35` and `mesh.layerMask = 2` , `35 & 2 == 2 != 0` so the mesh is visible from this camera.

So i mean the correct formula is :

> (mesh.layerMask & camera.layerMask) !== 0.

And if i’m right, there are only 32 combinations of masks which are excluding each others (if we are working with 32 bits).

Am i right or do i understand anything ?

Thanks for your answer.

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [June 4, 2025, 3:37pm UTC](https://forum.babylonjs.com/t/simulating-multiple-scenes/58785/8 "2025-06-04T15:37:54Z")

</div>

You are totally right! The doc is wrong!  
I’ll fix it!
