Download

Changing the ZOrder of a HorizontalBox inside a WidgetSwitcher?

The end goal here is to have a button in my UI that, on click, moves its container up in ZOrder and makes a Background Blur visible.

I have a widget hierarchy that goes Canvas -> Widget Switcher -> Horizontal box -> Horizontal Box. I want to change the ZOrder of the last Horizontal Box on button press (Or even just in the editor would be fine), but I can’t since it’s using a Horizontal Box Slot.

I tried casting it to a CanvasPanelSlot at runtime, but that cast fails. Is there some other way that I should be handling this?

Thanks!

Your cast fails as the very last HorizontalBox’ parent isn’t a canvas (it’s another horizontal box) so it cannot become a CanvasPanelSlot. You can nest canvases, though - try placing one between the HorizontalBoxes so the last one can refer to it’s parent as CanvasPanelSlot.

Untested. Should work in theory.

That definitely worked, but it didn’t solve my issue since setting the ZOrder of the last Horizontal Box didn’t bring it above the background blur. My eventual solution was to pull everything out of the first box and move it into a canvas, so that I could have the background blur and horizontal box on the same level of the hierarchy (If I left it inside the box, the background blur wouldn’t be able to expand to cover the rest of the content). Then, setting the ZOrder worked and brought my box above the blur.

Thanks for the help!