Does UMG ZOrder even work?

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?

1 Like

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.

1 Like

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.

1 Like

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.

3 Likes

ZOrder 是针对于 layer 之间的层级关系,修改ZOrder是修改整个layer的层级,层级内的UMG并不会改变层级,需要将UMG添加到另外的layer中,并修改layer的Zorder。

change SharedLayerName

This is precisely the way to do this. I have found that every widget added to the Viewport gets its own ZOrder. So, the simplest way to manage this is to have a Root widget that is the only one that is added to the Viewport and to add other widgets to this Root. You could have as many root widgets as you would like, but each one would have its own ZOrder.

However, the WidgetComponent handles this with SharedLayerName (as Hellow_Wd mentioned.) So things are already pretty easy if you are dealing with Actors.

For UI’s, though, a more complex and C++'-ey way would be to implement your own Layer management system via the IGameLayerManager. See WidgetComponent to understand how one might do this. This interface is not exposed to Blueprint.