# Getting mouse location in UMG

**URL:** <https://forums.unrealengine.com/t/getting-mouse-location-in-umg/594940>\
**Category:** UI\
**Tags:** unreal-engine, UMG\
**Created:** [July 1, 2022, 2:01pm UTC](https://forums.unrealengine.com/t/getting-mouse-location-in-umg/594940 "2022-07-01T14:01:15Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![SpiffyCS](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@SpiffyCS](https://forums.unrealengine.com/u/SpiffyCS)\
**Post date:** [July 1, 2022, 2:01pm UTC](https://forums.unrealengine.com/t/getting-mouse-location-in-umg/594940/1 "2022-07-01T14:01:15Z")

</div>

An explanation to the problem:  
I have a map widget which is a square, inside another widget’s Canvas Panel. The map widget holds all the functionality for the map like panning, zooming, etc. The map widget is comprised of an Overlay which the map image in, as well as another Overlay in that for POIs. What I am failing to create is making a waypoint marker at the mouse position when the mouse is clicked, and only in this map widget, and then be able to convert that position to the world (this conversion should be quite easy, it’s the getting the cursor position that I’m stumped on).

Anyway, I’m not overriding the mouse functions as I’m using Input Actions instead, so using Absolute to Local won’t work (to my knowledge, as it needs a geometry input that I don’t have). I’ve tried using Get Mouse Position from the Player Controller, and that doesn’t seem to work either, as it uses the whole screen size instead of this map widget’s size. I’ve also tried to Map Range the Get Mouse Position values to no avail.

Any responses would be appreciated!

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [July 1, 2022, 2:58pm UTC](https://forums.unrealengine.com/t/getting-mouse-location-in-umg/594940/2 "2022-07-01T14:58:30Z")

</div>

You will need to use widget geometry for this, otherwise it’s going to get really ugly.

> [@How can I manipulate world location through a minimap widget?](https://forums.unrealengine.com/t/how-can-i-manipulate-world-location-through-a-minimap-widget/469190/2):
>
> You can detect clicking on the world map by putting a clear widget button on top of it, and then detecting the cursor location on click. (remember to zero out the alpha on all the button images Normal, Highlight, Pressed, etc.) Then to drag you’ll need to use the Drag and Drop system built-in to Unreal. It has parameters to clip your object within the bounds of the map, drag the object around responsively, and then detect when it is dropped. There is a problem you’ll need to work around to have …

The mouse event spits out screen space, too - you translated it into the local coordinates of the widget (you may need to do it more than once if you have a nested hierarchy - windows inside windows…)

Once you have local coords and know world coords → MapRange is your friend.

* * *

> Anyway, I’m not overriding the mouse functions as I’m using Input Actions instead,

Perhaps you could explain the reasoning behind this choice. Sometimes there is a good one, other times it’s a dead end. Widgets are fine with processing input and this produces the necessary data for a lot of operations.

---

<div class="post-metadata">

**Author:** ![SpiffyCS](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@SpiffyCS](https://forums.unrealengine.com/u/SpiffyCS)\
**Post date:** [July 1, 2022, 3:24pm UTC](https://forums.unrealengine.com/t/getting-mouse-location-in-umg/594940/3 "2022-07-01T15:24:44Z")

</div>

I’m using Input Actions because the inputs from both keyboard, mouse and controller are customisable, and need to have those three instead of just the mouse. The link you sent looks similar to how I’d have done it if I did override the functions to get that geometry. Is there another way to the widget geometry that those functions provide without overriding them?

Edit: I’ll be using Common UI’s input system later on when concrete documentation or tutorials are available as currently it’s very lacking.

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [July 1, 2022, 3:40pm UTC](https://forums.unrealengine.com/t/getting-mouse-location-in-umg/594940/4 "2022-07-01T15:40:01Z")

</div>

![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/3/6/e36aa5f5aebca7e06e7215a84e5b0d1def4d270a.png)

You may be the target audience for this node.

* * *

Do note that widgets can also:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/5/d/55dca7489cf64192bdb4a697c966d5d63cd71555.png)

But I’ve never used it so not sure if that would help you. Worth looking into as an alternative if all else fails. Or maybe even before dealing with cached geometry.

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [July 1, 2022, 3:42pm UTC](https://forums.unrealengine.com/t/getting-mouse-location-in-umg/594940/5 "2022-07-01T15:42:10Z")

</div>

Also, you could store widget geometry during `onMouseMove` but process it only when controller action gets evoked. Not sure how different that would be from the cached one, though.

---

<div class="post-metadata">

**Author:** ![SpiffyCS](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@SpiffyCS](https://forums.unrealengine.com/u/SpiffyCS)\
**Post date:** [July 1, 2022, 4:01pm UTC](https://forums.unrealengine.com/t/getting-mouse-location-in-umg/594940/6 "2022-07-01T16:01:23Z")

</div>

Get Cached Geometry looks very promising. It seems I forgot I also need the Absolute Coordinate, which would be Get Screen Space Position, but I don’t have access to a Pointer Event Structure for that, as that would be from those overridden functions also. There doesn’t seem to be anything I can use outside of those functions for it either. I would set my own variable to one of the function’s inputs, but it’s that the mouse may never be used, so that variable will never get set in the first place, which I assume would break it.

---

<div class="post-metadata">

**Author:** ![JediKnightChan](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/jediknightchan/32/1156960_2.png) [@JediKnightChan](https://forums.unrealengine.com/u/JediKnightChan)\
**Post date:** [February 12, 2024, 5:49pm UTC](https://forums.unrealengine.com/t/getting-mouse-location-in-umg/594940/7 "2024-02-12T17:49:43Z")

</div>

This is what allows to do it in [0, 1] range

UPD: had some problems with it in not fullscreen full hd though, may need to include viewport scale factor or something like that

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/2/f/c2f24d4bf266af335a99b568c4ea396552529398.png)

---

<div class="post-metadata">

**Author:** ![DarkParasite47](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@DarkParasite47](https://forums.unrealengine.com/u/DarkParasite47)\
**Post date:** [July 18, 2024, 2:09pm UTC](https://forums.unrealengine.com/t/getting-mouse-location-in-umg/594940/8 "2024-07-18T14:09:01Z")

</div>

Thank for the solution, works like a charm!
