# Node in gui render order

**URL:** <https://forum.defold.com/t/node-in-gui-render-order/43989>\
**Category:** Questions\
**Created:** [February 20, 2019, 3:47am UTC](https://forum.defold.com/t/node-in-gui-render-order/43989 "2019-02-20T03:47:03Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![rinkowei](https://forum-defold.b-cdn.net/letter_avatar_proxy/v4/letter/r/7ea924/32.png) [@rinkowei](https://forum.defold.com/u/rinkowei)\
**Post date:** [February 20, 2019, 3:47am UTC](https://forum.defold.com/t/node-in-gui-render-order/43989/1 "2019-02-20T03:47:03Z")

</div>

How to control render order of node in gui compoent or game object component except set\_render\_order ? like adjust their sequence in file ?  
@britzl

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [February 20, 2019, 6:42am UTC](https://forum.defold.com/t/node-in-gui-render-order/43989/2 "2019-02-20T06:42:44Z")

</div>

> [@rinkowei](#):
>
> How to control render order of node in gui compoent or game object component except set\_render\_order

Game objects and gui components are two totally different things with different rules.

Visual components such as sprites, spine models, tilemaps etc are drawn [based on z-order](https://www.defold.com/manuals/graphics/#_z_order).

GUI components are given special treatment. In a gui the [draw order comes from the nodes hierarchy](https://www.defold.com/manuals/gui/#_draw_order) with the ancestors drawn before children (i starting at the root and ending with the leaf nodes on top). You can alter this behaviour through the use of layers in a gui. [Layers will give you increased control over the number of draw calls](https://www.defold.com/manuals/gui/#_layers_and_draw_calls) required to draw your gui.

gui.set\_render\_order() will control the order in which entire gui components are drawn.

The render script also controls what to draw and you can with custom materials draw stuff in multiple passes. But the rules of z-order is still in effect for every render.draw() call.

---

<div class="post-metadata">

**Author:** ![rinkowei](https://forum-defold.b-cdn.net/letter_avatar_proxy/v4/letter/r/7ea924/32.png) [@rinkowei](https://forum.defold.com/u/rinkowei)\
**Post date:** [February 20, 2019, 8:21am UTC](https://forum.defold.com/t/node-in-gui-render-order/43989/3 "2019-02-20T08:21:35Z")

</div>

If there are some guis in a gameobject, so what is their draw order ?

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [February 20, 2019, 8:41am UTC](https://forum.defold.com/t/node-in-gui-render-order/43989/4 "2019-02-20T08:41:11Z")

</div>

The default behaviour is that gui components are drawn after everything else. This can however be changed via the render script. The default render script will draw sprites, tilemaps and other components in world space, then switch to screen space and draw the gui.

---

<div class="post-metadata">

**Author:** ![rinkowei](https://forum-defold.b-cdn.net/letter_avatar_proxy/v4/letter/r/7ea924/32.png) [@rinkowei](https://forum.defold.com/u/rinkowei)\
**Post date:** [February 20, 2019, 8:43am UTC](https://forum.defold.com/t/node-in-gui-render-order/43989/5 "2019-02-20T08:43:29Z")

</div>

Ah… I mean how to control draw order of different guis in one gameobject ?

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [February 20, 2019, 8:45am UTC](https://forum.defold.com/t/node-in-gui-render-order/43989/6 "2019-02-20T08:45:12Z")

</div>

> [@rinkowei](#):
>
> how to control draw order of different guis in one gameobject

Using this:

> [@britzl](#):
>
> gui.set\_render\_order() will control the order in which entire gui components are drawn.

---

<div class="post-metadata">

**Author:** ![rinkowei](https://forum-defold.b-cdn.net/letter_avatar_proxy/v4/letter/r/7ea924/32.png) [@rinkowei](https://forum.defold.com/u/rinkowei)\
**Post date:** [February 20, 2019, 8:50am UTC](https://forum.defold.com/t/node-in-gui-render-order/43989/7 "2019-02-20T08:50:43Z")

</div>

Ah… No, I mean except set\_render\_order. As it stands, the first node to be added is the first to be displayed, right ?

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [February 20, 2019, 8:52am UTC](https://forum.defold.com/t/node-in-gui-render-order/43989/8 "2019-02-20T08:52:21Z")

</div>

> [@rinkowei](#):
>
> No, I mean except set\_render\_order. As it stands, the first node to be added is the first to be displayed, right ?

I’m sorry, I don’t think I understand what you are asking for. Can you please give a more elaborate example? I think I’ve answered all of the rules governing in which order guis are rendered on both a per gui component basis and on a node by node basis.

---

<div class="post-metadata">

**Author:** ![rinkowei](https://forum-defold.b-cdn.net/letter_avatar_proxy/v4/letter/r/7ea924/32.png) [@rinkowei](https://forum.defold.com/u/rinkowei)\
**Post date:** [February 20, 2019, 8:57am UTC](https://forum.defold.com/t/node-in-gui-render-order/43989/9 "2019-02-20T08:57:17Z")

</div>

Under the gameobject, add two gui component to it, so what is keep out relationship of them ? I mean which one will ward off another one ?

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [February 20, 2019, 9:05am UTC](https://forum.defold.com/t/node-in-gui-render-order/43989/10 "2019-02-20T09:05:49Z")

</div>

If you have two gui components in a single game object there is no rule that you should rely on when it comes to the order in which they are drawn. I believe that it is the order in which they are added to the collection that currently matters, but that is not something you should rely on. If you want to ensure that gui A is drawn above gui B then A must have a higher render order than B (set using gui.set\_render\_order). This is the only way that we will ever guarantee order between guis to be stable across Defold engine versions.

---

<div class="post-metadata">

**Author:** ![rinkowei](https://forum-defold.b-cdn.net/letter_avatar_proxy/v4/letter/r/7ea924/32.png) [@rinkowei](https://forum.defold.com/u/rinkowei)\
**Post date:** [February 20, 2019, 9:23am UTC](https://forum.defold.com/t/node-in-gui-render-order/43989/11 "2019-02-20T09:23:29Z")

</div>

OK, I got it, thank you.

---

<div class="post-metadata">

**Author:** ![Mathias\_Westerdahl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/mathias_westerdahl/32/228_2.png) [@Mathias\_Westerdahl](https://forum.defold.com/u/Mathias_Westerdahl)\
**Post date:** [February 20, 2019, 9:24am UTC](https://forum.defold.com/t/node-in-gui-render-order/43989/12 "2019-02-20T09:24:16Z")

</div>

But, you cannot use `gui.set_render_order()` to control separate GUI’s, right?

I think the option of having two game objects, each with a separate ´Z´value is both clearer and works at editor time.

---

<div class="post-metadata">

**Author:** ![rinkowei](https://forum-defold.b-cdn.net/letter_avatar_proxy/v4/letter/r/7ea924/32.png) [@rinkowei](https://forum.defold.com/u/rinkowei)\
**Post date:** [February 20, 2019, 9:35am UTC](https://forum.defold.com/t/node-in-gui-render-order/43989/13 "2019-02-20T09:35:49Z")

</div>

I use monarch framework in project, so if I show a collection, previous collection must to be warded off ? if there is a gameobject in previous collection which its ‘Z’ value is bigger than new collection ?

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [February 20, 2019, 9:53am UTC](https://forum.defold.com/t/node-in-gui-render-order/43989/14 "2019-02-20T09:53:59Z")

</div>

Z-value does not matter for gui components.

---

<div class="post-metadata">

**Author:** ![jfrangoudes](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/jfrangoudes/32/3358_2.png) [@jfrangoudes](https://forum.defold.com/u/jfrangoudes)\
**Post date:** [February 20, 2019, 10:39am UTC](https://forum.defold.com/t/node-in-gui-render-order/43989/15 "2019-02-20T10:39:43Z")

</div>

GUI’s are rendered in a separate render step after game objects have been rendered to the screen. To control the render order, you can either use set\_render\_order or you can create a separate render material for gui you want to render separately, change the render tag, and render it separately in the render file.

If you wanted the GUI render order based on game object Z coord, you could collect the z coords of game objects with gui components somewhere (like a module or another game object) and calculate the render order at runtime.
