# Rendering order of multiple entities of the same layer

**URL:** <https://forum.playcanvas.com/t/rendering-order-of-multiple-entities-of-the-same-layer/11970>\
**Category:** Help & Support\
**Created:** [January 31, 2020, 3:46pm UTC](https://forum.playcanvas.com/t/rendering-order-of-multiple-entities-of-the-same-layer/11970 "2020-01-31T15:46:40Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Helldubs](https://forum.playcanvas.com/letter_avatar_proxy/v4/letter/h/a88e4f/32.png) [@Helldubs](https://forum.playcanvas.com/u/Helldubs)\
**Post date:** [January 31, 2020, 3:46pm UTC](https://forum.playcanvas.com/t/rendering-order-of-multiple-entities-of-the-same-layer/11970/1 "2020-01-31T15:46:41Z")

</div>

I have a Ball that is made out of multiple entities/pieces so it can “explode” when losing the game.

I want the Ball to always be in the foreground since it’s destroying some platforms that fly away and they obscure the vision if they happen to fly in front of the ball.

I can make it so the Ball is in the foreground (layering + disabling depth test), however, when I do that the pieces of the ball interfere with each other and I can see the pieces in the back through the pieces in the front.

Got any ideas how to solve this?

---

<div class="post-metadata">

**Author:** ![wturber](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/wturber/32/5173_2.png) [@wturber](https://forum.playcanvas.com/u/wturber)\
**Post date:** [January 31, 2020, 6:14pm UTC](https://forum.playcanvas.com/t/rendering-order-of-multiple-entities-of-the-same-layer/11970/2 "2020-01-31T18:14:51Z")

</div>

It is a bit of a kludge, but maybe you can make the ball smaller and place it closer to the camera so it appears to be the same size. This should reduce the chances of the other pieces flying in front of the ball.

---

<div class="post-metadata">

**Author:** ![DevilZ](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/devilz/32/15506_2.png) [@DevilZ](https://forum.playcanvas.com/u/DevilZ)\
**Post date:** [February 1, 2020, 8:10am UTC](https://forum.playcanvas.com/t/rendering-order-of-multiple-entities-of-the-same-layer/11970/3 "2020-02-01T08:10:44Z")

</div>

Have you tried using Particle systems for the explode function instead @Helldubs?

---

<div class="post-metadata">

**Author:** ![Helldubs](https://forum.playcanvas.com/letter_avatar_proxy/v4/letter/h/a88e4f/32.png) [@Helldubs](https://forum.playcanvas.com/u/Helldubs)\
**Post date:** [February 2, 2020, 9:29am UTC](https://forum.playcanvas.com/t/rendering-order-of-multiple-entities-of-the-same-layer/11970/4 "2020-02-02T09:29:16Z")

</div>

This approach is sadly not possible since the view of the game is from the side. Making the ball smaller and the camera closer to the ball would make the whole fov wrong.

---

<div class="post-metadata">

**Author:** ![Helldubs](https://forum.playcanvas.com/letter_avatar_proxy/v4/letter/h/a88e4f/32.png) [@Helldubs](https://forum.playcanvas.com/u/Helldubs)\
**Post date:** [February 2, 2020, 9:34am UTC](https://forum.playcanvas.com/t/rendering-order-of-multiple-entities-of-the-same-layer/11970/5 "2020-02-02T09:34:45Z")

</div>

This might be a possible solution, although since I already have the Ball cut to pieces I thought I could use the work that I’ve already done. It’s not necessary though, so I am willing to try to do it with a particle system. To implement that I’d have to change the color of the particle system to fit the color of the ball (which is always changing), though. I know there is a way to change the color of the particle system via code but I couldn’t figure it out by myself yet. Would you or someone else mind giving a code example how to change the color of the particle system?

---

<div class="post-metadata">

**Author:** ![yaustar](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/yaustar/32/2268_2.png) [@yaustar](https://forum.playcanvas.com/u/yaustar)\
**Post date:** [February 2, 2020, 9:54am UTC](https://forum.playcanvas.com/t/rendering-order-of-multiple-entities-of-the-same-layer/11970/6 "2020-02-02T09:54:34Z")

</div>

I think you can do this with multiple layers and multiple cameras.

One camera for the main scene, and a second one for the ball. The second camera is rendering the layer for the ball only, 2nd in priority and clears the depth buffer.

---

<div class="post-metadata">

**Author:** ![DevilZ](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/devilz/32/15506_2.png) [@DevilZ](https://forum.playcanvas.com/u/DevilZ)\
**Post date:** [February 2, 2020, 1:47pm UTC](https://forum.playcanvas.com/t/rendering-order-of-multiple-entities-of-the-same-layer/11970/7 "2020-02-02T13:47:52Z")

</div>

> [@Helldubs](#):
>
> Would you or someone else mind giving a code example how to change the color of the particle system?

[This thread](https://forum.playcanvas.com/t/particlesystem-change-color-on-runtime/1653) might help you out.

---

<div class="post-metadata">

**Author:** ![Helldubs](https://forum.playcanvas.com/letter_avatar_proxy/v4/letter/h/a88e4f/32.png) [@Helldubs](https://forum.playcanvas.com/u/Helldubs)\
**Post date:** [February 3, 2020, 10:37am UTC](https://forum.playcanvas.com/t/rendering-order-of-multiple-entities-of-the-same-layer/11970/8 "2020-02-03T10:37:51Z")

</div>

I tried this but it didn’t work. The end result is the same as before, I can see the pieces through the ball.

I managed to come up with a pretty easy fix myself. I now just have a new sphere that acts as the ball and is disabled on death while the pieces are enabled and fly away.  
Thanks for trying to help, anyways 🙂

---

<div class="post-metadata">

**Author:** ![wturber](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/wturber/32/5173_2.png) [@wturber](https://forum.playcanvas.com/u/wturber)\
**Post date:** [February 3, 2020, 5:14pm UTC](https://forum.playcanvas.com/t/rendering-order-of-multiple-entities-of-the-same-layer/11970/9 "2020-02-03T17:14:18Z")

</div>

I just remembered this thread where the claim was made that you could put a 3D model into UI space. Perhaps that would work. I do know that 2D elements in UI space will layer over any of the 3D elements in world space. But this isn’t something I’ve tried with 3D models in UI space.

> [@\[SOLVED\] 3D model in UI?](https://forum.playcanvas.com/t/3d-model-in-ui/11682):
>
> Hi is it possible to have 3d models as part of the UI eg. custom 3d buttons (cube, sphere, etc…) for UI instead of 2D?

---

<div class="post-metadata">

**Author:** ![David\_Warren](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/david_warren/32/7233_2.png) [@David\_Warren](https://forum.playcanvas.com/u/David_Warren)\
**Post date:** [February 25, 2020, 4:03am UTC](https://forum.playcanvas.com/t/rendering-order-of-multiple-entities-of-the-same-layer/11970/10 "2020-02-25T04:03:02Z")

</div>

Wats the script for that

---

<div class="post-metadata">

**Author:** ![Helldubs](https://forum.playcanvas.com/letter_avatar_proxy/v4/letter/h/a88e4f/32.png) [@Helldubs](https://forum.playcanvas.com/u/Helldubs)\
**Post date:** [March 18, 2020, 8:24am UTC](https://forum.playcanvas.com/t/rendering-order-of-multiple-entities-of-the-same-layer/11970/11 "2020-03-18T08:24:34Z")

</div>

Sorry for the late anwser, but if it helps anybody.

```javascript
this.ball.enabled = false;
for(let index : number = 0; index < this.exploded.length; index++){
             this.exploded[index].enabled = true; //exploded are the different ballparts
             this.exploded[index].script.ballPart.Explode();
         }

```
