How to change the layering of nodes in a grid container?

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

inventory

I have a grid container which I am using for an inventory display. The problem is when the slots overlap, they are layered in the wrong way. I need the layering to be reversed, so that the highlighted slots are the ones on top. Usually I would just reorder the children in the scene tree, but doing so in this case would also change the order of the items in the grid container. I tried using canvas layers, but it also didn’t work (probably because they aren’t control nodes)

Does anyone have any ideas about how to solve this?

:bust_in_silhouette: Reply From: Lopy

Node2D inheriting Nodes have a z_index property that allows you to tweak what appears in front of what.

If it does not work, you can always make you own custom Container, to control exactly how things are placed.