Getting mouse position in UMG widget

I finally found something that might help.

In Tick and a few other Events for UMG widgets, there is a Geometry parameter that comes with it.
Pull out that pin and you can create a Local to Viewport node.

This allows you to transform between UMG-space coordinates and Touch coordinates. It might work for Mouse coordinates too because I think maybe they are in the same coordinate space.

I had to use this node to create my own touch joystick, since I had to make it non-focusable and visibility=Hit Test Invisible and check for touch info from the Player Controller whether it’s touching the joystick area or not, based on coords rather than the joystick widget itself (is a UMG button just can’t directly click it).

I have this custom UMG touch joystick working now, and am excited to try it out on mobile.

The main trick was that I did Local To Viewport on the UMG position coordinates and used the Pixel space output so I could compare them properly.

It got tricky when testing whether the touch is inside the joystick bounds I decided on, because I had to take one to the coord space of the other, find the difference, then take that back into viewport coords, then add the difference to the original, THEN compare the length of the 2d vectors. Whew!

2 Likes