# Stack panel z-index not working for GUI

**URL:** <https://forum.babylonjs.com/t/stack-panel-z-index-not-working-for-gui/20766>\
**Category:** Questions\
**Created:** [May 12, 2021, 12:57pm UTC](https://forum.babylonjs.com/t/stack-panel-z-index-not-working-for-gui/20766 "2021-05-12T12:57:37Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mitch](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@Mitch](https://forum.babylonjs.com/u/Mitch)\
**Post date:** [May 12, 2021, 12:57pm UTC](https://forum.babylonjs.com/t/stack-panel-z-index-not-working-for-gui/20766/1 "2021-05-12T12:57:37Z")

</div>

I am trying to give my stack panel higher z-index than the 3D button created in the scene. That is, the panel should appear in-front of the 3D button. But it seems to not have any effect. What is the issue here?

[https://playground.babylonjs.com/#XCPP9Y#7213](https://playground.babylonjs.com/#XCPP9Y#7213)

---

<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:** [May 12, 2021, 3:34pm UTC](https://forum.babylonjs.com/t/stack-panel-z-index-not-working-for-gui/20766/2 "2021-05-12T15:34:11Z")

</div>

So this is because the 2D GUI is on a plane on top of main scene and the 3D gui is on top of all of that (think about multiple layers).

The best option I can see here would be to create a second scene just for the 2D gui

---

<div class="post-metadata">

**Author:** ![Mitch](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@Mitch](https://forum.babylonjs.com/u/Mitch)\
**Post date:** [May 17, 2021, 7:49am UTC](https://forum.babylonjs.com/t/stack-panel-z-index-not-working-for-gui/20766/3 "2021-05-17T07:49:36Z")

</div>

@Deltakosh Hmm alright. But I thought the z-index would come in handy here. Does it not?

Also for such a case, the screen space 2D buttons should be given a higher importance than 3D buttons placed in the world space, right?

---

<div class="post-metadata">

**Author:** ![Mitch](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@Mitch](https://forum.babylonjs.com/u/Mitch)\
**Post date:** [May 17, 2021, 2:12pm UTC](https://forum.babylonjs.com/t/stack-panel-z-index-not-working-for-gui/20766/4 "2021-05-17T14:12:24Z")

</div>

@Deltakosh

Is this the way to create overlay for the 2D buttons - stack panel?  
I have tried to create the second scene but I guess I am doing something wrong.

[https://playground.babylonjs.com/#XCPP9Y#7299](https://playground.babylonjs.com/#XCPP9Y#7299)

---

<div class="post-metadata">

**Author:** ![mawa](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mawa/32/12384_2.png) [@mawa](https://forum.babylonjs.com/u/mawa)\
**Post date:** [May 17, 2021, 2:23pm UTC](https://forum.babylonjs.com/t/stack-panel-z-index-not-working-for-gui/20766/5 "2021-05-17T14:23:17Z")

</div>

> [@Deltakosh](#):
>
> So this is because the 2D GUI is on a plane on top of main scene and the 3D gui is on top of all

Correct. More details here:

> **[In-Depth layerMask | Babylon.js Documentation](https://doc.babylonjs.com/features/featuresDeepDive/scene/layermask)**
>
> Learn how the layerMask property work accross the library

> [@Deltakosh](#):
>
> The best option I can see here would be to create a second scene just for the 2D gui

Sry to object here, Boss;) I studied this part with guru;) @Evgeni_Popov and I guess I can say the recommended option would be to order the 3D layer (scene) so that it shows behind the advanced texture of the 2D GUI, using a 2 cams approach, as demonstrated in this PG:

> **[Babylon.js Playground](https://playground.babylonjs.com/#MFN0FQ%231)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

---

<div class="post-metadata">

**Author:** ![Mitch](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@Mitch](https://forum.babylonjs.com/u/Mitch)\
**Post date:** [May 17, 2021, 2:30pm UTC](https://forum.babylonjs.com/t/stack-panel-z-index-not-working-for-gui/20766/6 "2021-05-17T14:30:30Z")

</div>

Thanks!

I got it working with two cameras:

[https://playground.babylonjs.com/#XCPP9Y#7300](https://playground.babylonjs.com/#XCPP9Y#7300)

---

<div class="post-metadata">

**Author:** ![mawa](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mawa/32/12384_2.png) [@mawa](https://forum.babylonjs.com/u/mawa)\
**Post date:** [May 17, 2021, 2:32pm UTC](https://forum.babylonjs.com/t/stack-panel-z-index-not-working-for-gui/20766/7 "2021-05-17T14:32:06Z")

</div>

Happy to hear that. You are very welcomed 😃

---

<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:** [May 17, 2021, 5:50pm UTC](https://forum.babylonjs.com/t/stack-panel-z-index-not-working-for-gui/20766/8 "2021-05-17T17:50:29Z")

</div>

2 cameras or 2 scenes are kind of ok here 😉  
2 cameras is probably more performant so good job ;D

---

<div class="post-metadata">

**Author:** ![Mitch](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@Mitch](https://forum.babylonjs.com/u/Mitch)\
**Post date:** [May 18, 2021, 8:51am UTC](https://forum.babylonjs.com/t/stack-panel-z-index-not-working-for-gui/20766/9 "2021-05-18T08:51:13Z")

</div>

Thanks @Deltakosh but can I request a feature? 🙂  
That is instead of creating 2 cameras for such a case, can we use the z-index of 3D GUI and 2D GUI and then use the higher z-index of the GUI element to keep that in front?

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [May 18, 2021, 10:22am UTC](https://forum.babylonjs.com/t/stack-panel-z-index-not-working-for-gui/20766/10 "2021-05-18T10:22:09Z")

</div>

It is not possible because the GUI and 3D GUI are two separate modules that don’t know each other. In addition, there’s no z-index in the 3D GUI as the display order is simply the meshes location in the 3D space.

---

<div class="post-metadata">

**Author:** ![mawa](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mawa/32/12384_2.png) [@mawa](https://forum.babylonjs.com/u/mawa)\
**Post date:** [May 19, 2021, 8:56am UTC](https://forum.babylonjs.com/t/stack-panel-z-index-not-working-for-gui/20766/11 "2021-05-19T08:56:54Z")

</div>

LoL. Yes, of course. My comment was only because you stated “…the best option…”. 😉  
It’s not mine to tell you that in BJS there is (nearly) always an alternate way and both would work like a charm 🧙 😄
