get a widget's location in screenspace

Hello,
You can use “set position in viewport” to set location of a widget in viewport (don’t forget to set z order higher than main widget).

2 Likes

All mouse and keyboard events send the geometry of the widget.

Yeah, the problem is that I’m manually setting focus on widgets in a scroll box using an index since I need controller input. The buttons never get hovered or mouse events, they just get their properties set based on manually managing what should have focus.

I think the focus event also sends geometry.

Can anyone please answer this question with a very simple example?

is there a way to do this line of thought:
i need to move an object i just created to buttonX.viewportLocation + (x,y)

It’s not simple. Slate does not allow access to widget geometry outside of the event/layout pass where the geometry is stable and you can make the correct calculations without introducing layout loops. The only widget who gives you access to their geometry is your own, during the Tick or the events where the geometry is available.

1 Like

This is what I’ve been playing around with. For now I’m just outputting to a print string. I’d assume that converting 0,0 in the geometry from local to absolute would return the upper left corner of the widget in screen space. My test case has a widget embedded in a border, and the tick->geometry check is being performed by the widget within the border.

That value should be 124,124 in my test scenario. The value I’m getting is 433,284, which is the location of the yellow circle in the attached image. I can manually mess with values from that to push that dot back to the location I want via trial and error, but if I could figure out how those values are created, I could probably come up with something more reliable. I’m obviously misunderstanding something here… but I can’t figure out what.

localOffset.png

Ok… so it looks like the values it outputs assumes a 1080p resolution. When I full screen and test at 1080p, I get the values I would expect. I guess I need to multiply the output values against the resolution scale of the current UI.

Now to find where that’s stored.

The absolute coordinate is in desktop space that’s why it works in fullscreen. You’d need remove the viewport’s inverse transform, to get it in viewport space. Though I don’t know if that transform is readily available.

I’ve added some utility functions to ML to help with this in the future, if you want to grab the code and throw it into your own utility BP library, here’s the changelist.

https://github.com/EpicGames/UnrealEngine/commit/56a1390541ffead1fc33a7aefe809abdc9f17e77

The functions will give you the position in both viewport space and screen space. viewport is like pre DPI scaling space of widgets. Screen is, canvas land, pixels, ray casting land…etc.

To revive an ancient thread, I’m now doing this using the Menu Anchor system. It seems to be working well and addresses my issue.

To revive an ancient reply to revive an ancient thread, how did you get the menu anchor to appear over an item that is outside the UI (player etc)?

To revive an ancient reply to revive an ancient thread reply used to revive an ancient thread, how did you revive an ancient thread like this ?

Hey, stuck bug, did you use a scroll box or a list view in the widget? Also, how can you get the list view to display?

Decided to answer this since this is the first post that pops up in google and it still hasn’t been answered.

6 Likes

What are you using to feed the “Widget Position”?

4 Likes

Solutions posted here didn’t help me, so I’ve decided to revive this thread for anyone finiding it, looking for an answer (like me, recently).

In my case I wanted to create a widget in a position of another widget, but it should also work with moving widget around.

First of all, this is the post that helped me

And this is my implementation:

15 Likes

All hail @Lordlolek, solver of ancient mysteries. Thank you!

1 Like

The question is asking how to get the position, not set

I faced this same issue when testing out a custom tooltip issue and this is the solution I came up with. It will work at any screen ratio and scale.


get the cached geometry of the widget you want to use as a reference to set location.


Use that location to set the location of your new widget. Here I use a canvas panel
to have anchor control.

image
perfect alignment with an offset exactly the size of the referenced widget.
Nothing is hardcoded, so the method can be used to update its location to anything.

I hope this helps solve the issue
:slight_smile:

1 Like