Does UMG ZOrder even work?
Does UMG ZOrder even work?
04-09-2017, 03:14 AM
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?
Tags: None
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.
(2)
Unreal Engine 4 Documentation > Unreal Engine Blueprint API Reference > Layout > Canvas Slot > Set ZOrder
https://docs.unrealengine.com/en-US/BlueprintAPI/Layout/CanvasSlot/SetZOrder/index.html
(3)
UMG widgets ordering
https://answers.unrealengine.com/questions/134523/view.html
4 1 | When im adding widgets to CanvasPanel in UMG editor they dont respect displaying order. In example above i was adding Image widgets directly to canvas panel, each image was moved to the right and down. As you can see brown and light red images are drawn in bad order. Even worse, when adding another image, order of those already added is mixed up: As you can see Turquoise image now is in front, and only thing i did was adding new image to canvas. Am i doing something wrong? Z-Order in all of those images is default that is 0, and im aware that i can adjust their draw order by changing Z-Order but i think that images that are added in certain order, and are displayed in that order in hierarchy, should respect that hierarchy when drawing. Also i dont see any way to change widget position in hierarchy (or to choose place where new widget should be in hierarchy). It seems like if i have 10 widgets on canvas and i want to swap hierarchy order of widgets 3rd and 7th only way is to remove them from parent and placing them once again in different order. Product Version: Not Selected 标签:bug reporteditorumgquestion1.png (15.7 kB) 2.png (15.5 kB) 更多 ▼ 已提出 Nov 18 '14 在 6:39 PM Jakub Gałecki BaronPumpky Nov 25 '14 在 5:40 AM 1 I'm curious about this as well! I've been learning UMG for a few weeks and this has plagued me ever since I started. |
2 | Hello Jakub Gałecki, You would be correct in assuming that you will need to set the Zorder for everything on your Designer tab that overlaps. Hierarchy does not necessarily determine what shows as on top. As for rearranging widgets in the hierarchy, you will need to click and drag them. When dropped on a widget that can hold it as a child widget the widget will then be placed under it. You can also reorder the widget by clicking and dragging them upward in the hierarchy. 更多 ▼ 已解答 Nov 25 '14 在 6:02 AM |
1 | It seems to be a bug. UIs might be drawn in order in hierarchy among the same ZOrdered UIs. But in UE4 engine codes, I found codes not to preserve the order in hierarchy while trying to sort by ZOrder. The codes are at SConstraintCanvas.cpp - 79 lines. (SConstraintCanvas::OnArrangeChildren, Engine Ver. 4.8.2)
This line should be corrected to below.
After I rebuilt the engine, it worked in the way I thought. |