How can I make a UI object being dragged appear on top of all other UI objects?

In this screenshot, you can see the initial setup in the Scene view of the hierarchy.

When I run the game and try to drag the Item (potion), it renders behind Slot(1).

When I drop onto Slot(1), however, the parent of the Item (potion) becomes Slot(1) and it then renders on top of Slot(1).

When I drag back toward the original Slot, however, it now appears behind it unless I “drop” it there, causing the parent to change once again.

One obvious solution to this appears to be changing the parent following an OnPointerEnter event on a Slot. I am hoping that there might be an even simpler alternative, though. Is there something I have overlooked?

I don’t think there is. The hierarchy order (parentage) controls the draw order, so to make the dragged item appear on top, you’ll have to change the parent during the drag.

There are more extreme solutions, such as having an entirely different Canvas for the stuff you’re dragging, but to make use of that would require changing the parent as well.

1 Like

I would throw an empty GameObject as the last item in your canvas hierarchy. They when dragging you can parent the dragged object to that.

1 Like

It’s a very clever answer. Thank’s a lot… But you must do GameObject sibling index last!