From the docs, about Y-sort:
Nodes kind relative to one another provided that they’re on the identical
z_index
.
So, it’s essential to set the identical Z-index for siblings Nodes you need to Y-sort as properly.
Each Z-index and Y-sort are used to override Tree order for rendering functions, however they work considerably in another way.
-
Z-index assigns an arbitrary “rendering precedence” to Nodes, drawing higher-index Nodes in entrance, and falls again to Tree order when drawing same-index Nodes (until Y-sort is enabled). Pattern use case: you’ll be able to force-draw particles in entrance of all the pieces else presently seen, or draw a sword behind a personality regardless of the previous being a Third-level youngster Node of the latter.
-
Y-sort assigns a dynamic “rendering precedence” based mostly on the vertical place of a Node’s youngsters (for siblings you will want a typical ancestor), and is affected by Z-index sorting. Pattern use case: you’ll be able to accurately Y-sort floating, grounded, and underwater objects sharing the identical direct mum or dad as an alternative of managing three completely different Nodes for that, by merely utilizing completely different Z-indices.
Please word that utilizing Z-index extensively might impression your recreation’s efficiency, because it requires reordering draw calls earlier than sending them to the GPU.