Node in gui render order

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

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.

GUI components are given special treatment. In a gui the draw order comes from the nodes hierarchy 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 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.

2 Likes

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

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.

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

Using this:

Ah… 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.

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 ?

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.

1 Like

OK, I got it, thank you.

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.

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 ?

Z-value does not matter for gui components.

1 Like

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.