Hi,

I have an inventory and it has two major groups in UI: Weapons and Potions. They both have multiple child objects.

In hierarchy weapons stay below potions. It means that its children will always appear above potions children.

I’m implementing drag&drop. So when I drag a potion - i’m setting it as last sibling and it will appear above all other potions. But when I hover over weapons - it will render under them because weapons parent is below in hierarchy.

Is there a way to directly tell dragged potion to render above all other UI elements or I need to fiddle with parents - change they order in hierarchy every time an item is dragged?

You should keep a reference to the layer of the hierarch that you want a potion (or weapon) to be. This may require some minor but manageable changes to your hierarchy.

So:

  1. In your hierarch make sure you have two empty gameobjects for the layers. It should look like this:

60196-inventoryexample.png

  1. In your script either create a public variable to assign the layer to from the unity editor inspector, or find the layered object like so: PotionLayerReference = GameObject.Find(“PotionLayer”);
  2. When you want to place your weapon or potion object on the specific layer, simply attach the desired object to that referenced layer. That should put it on the just below the layer object.

Like so: HealthPotionTwo.transform.setParent(PotionLayerReference);

This is so stupid.
I managed to solve problem with weapons and potions but now have to solve problem with other UI elements since:

-if I put inventory at the bottom of hierarchy - its elements will overlap other UI elements

-if I put higher - items won’t appear correctly when dragging

Now I feel that I need to write some kind of hierarchy manager just to make UI appear correctly.