- Home /
[UI] Grid Layout Group Custom Sort Order
I am working on a Grid based button UI that uses the Grid Layout Group to position the elements. When one of the buttons is selected it extends, covering up the button to the right of it, to display more information.
The problem is because Unity uses the hierarchy to sort UI elements and because the Grid Layout Group overrides the hierarchy order of its children resulting in my button always appearing behind the button to the right of it.
If I try to reorder the elements myself at runtime the Grid Layout Group will move the position of the buttons to reflect the same ordering convention as before.
Grid Layout Group
- Element (1) [x: 1, y: 1]
- Element (2) [x: 1, y: 2]
- Element (3) [x: 2, y: 1]
[After runtime ordering]
Grid Layout Group
- Element (3) [x: 1, y: 1]
- Element (2) [x: 1, y: 2]
- Element (1) [x: 2, y: 1]
[Desired Result]
Grid Layout Group
- Element (3) [x: 2, y: 1]
- Element (2) [x: 1, y: 2]
- Element (1) [x: 1, y: 1]
Any advice would be much appreciated.
Answer by Tourist · Feb 22, 2017 at 10:01 AM
Use canvas component to modify the order of the selected button.
keywords : sortOrder, sortingLayers.
Do you mean add a canvas component to the selected button?
Either you add it via your script or you add it via the editor. But yes, if your buttons have canvas component, you can use sortOrder to modify the rendering order.
Your answer
Follow this Question
Related Questions
Vertical Layout with Pixel Perfect scaling 0 Answers
Scale Layout elements to fit screen 2 Answers
Layout error after crash has effected canvas scaling 1 Answer
Why doesn't childing a gameobject to GridLayoutGroup at runtime align it properly? 1 Answer
Display loaded UI Image in Container with native size 0 Answers