I have a widget that I display when the user mouses over parts of the UI, kind of like a tooltip, but with my own custom features. Anyway, I add this “tooltip” widget to the viewport and I give it a ZOrder of some high number, like 100 or 1000. However it never draws on top of the other widgets in the viewport. It doesn’t matter what I set the ZOrder to it always draws in the same order. The only solution I’ve found is to remove it from the viewport and then add it back to the viewport again. This puts it on top over everything else, even if I leave its ZOrder set to 0. Does the ZOrder not work? Is it a bug or a known issue? Is there any disadvantages to removing from and then adding again to the viewport?
I actually have the same issue and I don’t know of a good solution.
The disadvantage of removing and adding is that you pay a cost in performance whenever you add a widget to viewport. The cost is very small if the widget is lite, say just some border with text in the cast of a tooltip so it’s acceptable. In my case I remove and add an inventory with a 100 slots, that is buttons with textures, and it is very noticeable.
The Z Order works for elements inside of the same widget.
Widget ordering will come from the order you add them to the viewport.
Right. I kind of came to this conclusion as well after fiddling with it. The strange thing is that I’m adding my tooltip widget to the viewport last, so it “should” be on top of everything else, but it isn’t. It is on top of some widgets, but not others. To fix the problem, I have to wait a Tick, then remove the tooltip widget from the viewport, then add it back in. Really weird.
The general idea behind it is to have a master widget with a canvas covering the area where the widgets are to be zOrdered and add it to the viewport. Whenever you create gameplay widgets, instead of adding them to the viewport as usual, add them as children of the master widget’s canvas (masterWidget → Canvas → AddChildToCanvas). This will allow you to control their position, size and, most importantly, the zOrder. In other words, what BrUnO said.