UMG: element position in screen view coordinates

Hi!

I have UserWidget created in vertical box. How can I obtain position of that element in screen view coordinates? I need to draw another element near it, on another layer.

That’s a difficult thing to determine in Slate and by extension UMG, it’s impossible to determine where a widget will be until it’s there. And the only widgets who knows where they are that frame is the widget and its parent. We pass geometry information in through Tick, which is technically not their permanent location, as further changes in that Tick could change its final location. So the final geometry is passed in to the Paint call to the widget. We expose it in UMG, but what has been exposed may be not enough. You can take a look, give it a try and see if it works.

Are you trying to do like a tool-tip/popup near it?

Generally the way we’ve solved this in Slate is we’ve created several widgets that manage this complexity for us. We’ve created things like the Menu Anchor widget that lets us make popups/dropdowns…etc that contain widget that is always on screen, and then they defer draw the element you want to pop up after everything else is drawn. The wrapper for it for UMG is coming in 4.6. If you need it before then, you’ll have to grab it from Github.

The other option is to roll your own Slate widget and then wrap it with a UWidget for UMG. The golden path in Slate is to generally build a dedicated widget that does the special layout you need in some reuse-able way, because of the transient nature of layout, and because making it a special widget ensures the hierarchy of dependency is respected. If you just cache position in Tick or Paint and allow anyone to query it to place their widget near yours, you’re inviting frame behind issues if you can’t guarantee the tick/paint order due to hierarchy/parentage.