When should I use "Z index as relative"

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By SebSharper

Hi there. I am making a 2D game, but I have had some issues with the z-index, sometimes it draws the sprites in an order that is the one that I am not expecting. This made me think that maybe it has something to do with the property “Z Index as relative” that is toggled on by default. Can someone explain me when should I toggle this property and when not to?

:bust_in_silhouette: Reply From: jgodfrey

As documented…

If true, the node’s Z index is relative to its parent’s Z index. If this node’s Z index is 2 and its parent’s effective Z index is 3, then this node’s effective Z index will be 2 + 3 = 5.

So, really, when checked, it lets you easily organize the z-index of a hierarchy of nodes relative to their parent. Then, you can easily adjust the entire hierarchy relative to other objects in the world simply by changing the z-index of the parent node(s) (and all the “relative” children will adjust automatically).

Really, it’s just a convenience mechanism. You’ll need to decide if it’s helpful or not to use it in a given situation.