- Home /
How can I keep a UI element in the front while keeping hierarchy strict?
SO a quick run down. I am using an object which is a UI Dropdown Menu.
I have so far setup my UI elements in such a way that it is strictly hierarchical for organization. Now my question is there anyway I can get it to display at the upfront most way or do I have to reorganize the hierarchy to force it to work. I want to keep the hierarchy the same as it just neater and easy for prefabs to workout.
I checked on another post about this issue and the solution was to drop a Canvas component on the object, however that did work visually, but none of the buttons would respond.
Attached is a picture of the current hierarchy involved as an example.
Answer by npatch · Nov 04, 2015 at 08:12 AM
You can't do hierachy by role under Canvases. The reason being that the order of the transforms makes up the order with which the UI elements are drawn.
back_button will be drawn before title_text.
The elements under item1_edit will be drawn after the elements of item1_dropdown.
So if things aren't working for you, it's probably because you are using the wrong logic for organizing your UI elements.
It's best if you don't drop Canvases inside Canvases. You could have Canvases in the same depth(same parent) and make sure they have different distance from the camera, if you want to keep things as they are.
Also keep in mind that if you have UI elements with nested overlapping graphics and lose pointer events in the smaller graphic, chances are it's used up by the first graphic the pointer encounters.
So, from the provided picture above, how would you reorganize them to have the dropdown display properly? Don't need to show all of them just ones pertaining to dropdown if that is alright with you. I thought I had an understanding on the UI depth with hierarchy but I suppose not. The approach I took initially was to parent the objects as if they were actually "in-game" objects which seems to not work for a UI-basis.
Depends on what you want to show above the others and what kind of editing you do in the item1_edit group.
So far the text do not worry about overlapping one another. The main issue I want to resolve is having the dropdown be the top most UI visible over all other UI elements.
Answer by meat5000 · Nov 04, 2015 at 08:36 AM
http://docs.unity3d.com/ScriptReference/Transform.SetAsLastSibling.html
I could be wrong but this sounds like what you need.
There is also a Pos Z entry in the rectTransform. This moves elements into and out of the canvas.
Isn't it a bit of a waste to change indeces at runtime when you can change the order at design time? $$anonymous$$oreover it should make it easier for you to see problems of occlusion between elements.
This simply brings the element to the front on screen. $$anonymous$$akes it draw last to stay on top.
I know what it does, what I'm saying is, he might be using the wrong way of organizing things so this could get messy if it's needed in multiple places. If it's just one element that's having a problem okay, but I think it's better to change his way to benefit in the longrun. What do you think?
These are great I will definitely try them out. For the time being this specific instance of UI elements is a one time deal as far as I am aware of, however in regards to the dropdown menu UI I will have better practice in organizing the UI elements.