- Home /
4.6 UI - overriding order / depth
So in 4.6 UI, the decision of which UI element is drawn on top of another depends on the hierarchy, but I'm looking a way to override this.
I have an inventory panel, displaying a bunch of items in a table. Each item has an image, which doesn't overlap other items. In addition, each item has a text component that is displayed when hovering the item, and this component does overlap other items. I want the text component to always be on top of the item images, even other items.
So the hierarchy would look like this:
Image 1
Text 1
Image 2
Text 2
And as such, Image 2 will be on top of Text 1. How do I override this so that all Text elements are drawn on top of all Image elements? I tried modifying Z position but it didn't help. In NGUI this would be easy by setting the Depth parameter of Text higher than that of Image.
Edit: Here's a screenshot of the problem
The bow & it's text are Item 1 in the hierarchy above, and the uzi is item 2 (it's text is disabled)
Any Ideas? I'd prefer not to instantiate a popup every time...
Answer by DiegoSLTS · Mar 12, 2015 at 01:08 PM
I don't know any method to change that drawing order, the only solution I can think of is using only one text box at the end of the hierarchy and displaying and moving it over the hovered element.
You don't need to instantiate a popup every time, you can use the same and just move it and change the text according to the hovered element before showing it.
Yeah, thats what I meant, I was just thinking this is something that must have a solution with the UI without having to reposition children... I'll leave it open a bit more to see if anyone can come up with a solution for setting the depth, as could be done in NGUI.
The only thing I know that affects the drawing order in UI elements is the "Sort order" property of the Canvas component.
Another solution might be to move the hovered element as the last child of the parent element with code, it will keep it's position in the scene if it's not a child of a Grid/Horizontal/Vertical Layout component.