# Getting mouse position in UMG widget

**URL:** <https://forums.unrealengine.com/t/getting-mouse-position-in-umg-widget/392216>\
**Category:** UI\
**Tags:** project-world-locati, unreal-engine, Widget, question, Blueprint, UMG\
**Created:** [April 29, 2017, 4:40am UTC](https://forums.unrealengine.com/t/getting-mouse-position-in-umg-widget/392216 "2017-04-29T04:40:31Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![theonecalledtom](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@theonecalledtom](https://forums.unrealengine.com/u/theonecalledtom)\
**Post date:** [April 29, 2017, 4:40am UTC](https://forums.unrealengine.com/t/getting-mouse-position-in-umg-widget/392216/1 "2017-04-29T04:40:31Z")

</div>

Recently I started playing with UMG. Seems like it has a lot of potential make some pretty good looking UI.

One thing I’ve run into though is getting the touch position within a widget. Basically I have and image that I want players to roll their fingers (or the mouse pointer) across and it 1) animates depending on the touch position and 2) provides game play code with the information about where the player is touching.

Animating was easy, but either getting the touch location or the widget screen coords so gameplay can work out where they are touching and drive the animation is proving difficult.

Two options:

1. How do I get a widget position in AHUD::DrawHUD(UCanvas\*) coords?
2. How do I get the mouse pointer into widget coords (really I want a 0-1 result on each axis)?

I’m hoping the state of the art is further along than the big blueprint functions I’m seeing in my searches.

---

<div class="post-metadata">

**Author:** ![Two-faced](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Two-faced](https://forums.unrealengine.com/u/Two-faced)\
**Post date:** [April 29, 2017, 12:49pm UTC](https://forums.unrealengine.com/t/getting-mouse-position-in-umg-widget/392216/2 "2017-04-29T12:49:19Z")

</div>

1. 

![136081-2017-04-29_19-44-28.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/7/7/077e8fe2d2ae771dd2c89fa27bfdd61480c3c4ec.png)

1. As for the 2d question. Do you need to get coords at the runtime? I mean do your widgets move in-game?

---

<div class="post-metadata">

**Author:** ![theonecalledtom](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@theonecalledtom](https://forums.unrealengine.com/u/theonecalledtom)\
**Post date:** [April 30, 2017, 4:43am UTC](https://forums.unrealengine.com/t/getting-mouse-position-in-umg-widget/392216/3 "2017-04-30T04:43:31Z")

</div>

Regarding 1) it’s not the mouse position I need - as you point out that is trivial. It’s the widget position in screen space, OR the mouse position in widget space.

Regarding 2) Widgets may move, may not… right now I’m trying to work out if the coordinate mapping can be done easily.

My app UI is custom, and fairly simple. I have my own C++ concepts of widgets and my own image widgets, buttons, scrolling lists etc. UMG however is significantly more robust and _exposed to blueprint_, so I’m trying to learn the ropes.

In this case I have a car steering wheel and the user drags it around to interact. Would be trivial in my own system but I want to do this in UMG.

---

<div class="post-metadata">

**Author:** ![Two-faced](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Two-faced](https://forums.unrealengine.com/u/Two-faced)\
**Post date:** [April 30, 2017, 5:46pm UTC](https://forums.unrealengine.com/t/getting-mouse-position-in-umg-widget/392216/4 "2017-04-30T17:46:30Z")

</div>

I apologize, I saw there mouse position somehow…  
1)

![136213-2017-05-01_00-43-50.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/5/1/a5191096f55662c2e740f11e91ac9f297c3f7337.png)

1. I believe now you can found mouse position in widget coords

Good luck!

---

<div class="post-metadata">

**Author:** ![Two-faced](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Two-faced](https://forums.unrealengine.com/u/Two-faced)\
**Post date:** [May 1, 2017, 7:19pm UTC](https://forums.unrealengine.com/t/getting-mouse-position-in-umg-widget/392216/5 "2017-05-01T19:19:43Z")

</div>

Do you still need any help?

---

<div class="post-metadata">

**Author:** ![theonecalledtom](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@theonecalledtom](https://forums.unrealengine.com/u/theonecalledtom)\
**Post date:** [May 1, 2017, 10:10pm UTC](https://forums.unrealengine.com/t/getting-mouse-position-in-umg-widget/392216/6 "2017-05-01T22:10:38Z")

</div>

Led me in the direction of getting a result via UMG, though more complicated that seems necessary - as you have to convert positions and sizes using anchor points to get screen space information.

I’d like a function - GetFinalLocation( FVector2d &outMin, FVector2d &outMax ) or something similar.

[These functions](https://github.com/EpicGames/UnrealEngine/commit/56a1390541ffead1fc33a7aefe809abdc9f17e77) might be close (as seen in [this thread](https://forums.unrealengine.com/showthread.php?69025-get-a-widget-s-location-in-screenspace)), but when I printed out their results I didn’t understand that UMG was thinking of my Y value as being -ve from its anchor at the bottom of the screen.

Will revisit that when I next look at the code!

---

<div class="post-metadata">

**Author:** ![Two-faced](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Two-faced](https://forums.unrealengine.com/u/Two-faced)\
**Post date:** [May 1, 2017, 10:27pm UTC](https://forums.unrealengine.com/t/getting-mouse-position-in-umg-widget/392216/7 "2017-05-01T22:27:52Z")

</div>

I’m sure you gonna figure all out! Good luck!

---

<div class="post-metadata">

**Author:** ![mightyenigma](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@mightyenigma](https://forums.unrealengine.com/u/mightyenigma)\
**Post date:** [March 9, 2018, 1:20am UTC](https://forums.unrealengine.com/t/getting-mouse-position-in-umg-widget/392216/8 "2018-03-09T01:20:57Z")

</div>

figure it out yet? I need this too

---

<div class="post-metadata">

**Author:** ![theonecalledtom](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@theonecalledtom](https://forums.unrealengine.com/u/theonecalledtom)\
**Post date:** [March 9, 2018, 5:35am UTC](https://forums.unrealengine.com/t/getting-mouse-position-in-umg-widget/392216/9 "2018-03-09T05:35:12Z")

</div>

Fraid I changed my design to avoid the problem. There were some large networks out there that people were saying might solve it so have a search and you may find the answer… ☹ Sorry not to be much use!

---

<div class="post-metadata">

**Author:** ![mightyenigma](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@mightyenigma](https://forums.unrealengine.com/u/mightyenigma)\
**Post date:** [March 9, 2018, 4:40pm UTC](https://forums.unrealengine.com/t/getting-mouse-position-in-umg-widget/392216/10 "2018-03-09T16:40:34Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Nizami\_Nz](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Nizami\_Nz](https://forums.unrealengine.com/u/Nizami_Nz)\
**Post date:** [October 22, 2020, 7:11am UTC](https://forums.unrealengine.com/t/getting-mouse-position-in-umg-widget/392216/11 "2020-10-22T07:11:07Z")

</div>

Hello. I found the answer to this question. The system works without fail regardless of (Anchors) or (Screen Size). Hope I could help you !!!

 ![319609-tocenter.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/8/9/d89fe11bfd6f15f2df69d69c3d4dc1941e421f87.jpeg)

---

<div class="post-metadata">

**Author:** ![Talad](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Talad](https://forums.unrealengine.com/u/Talad)\
**Post date:** [April 9, 2024, 9:10am UTC](https://forums.unrealengine.com/t/getting-mouse-position-in-umg-widget/392216/12 "2024-04-09T09:10:18Z")

</div>

Hi,  
I’m adding here my answer to get the mouse position inside a canvas which has a scrollbox.

I made a video for it, as the other answers I found including this post didn’t full solve my problem.

[![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/d/a/7da6f5f1f91c8a0922506f6397dc8ab2307e086f.jpeg "Unreal Engine - Mouse Position Inside Scrollbox Widget Canvas") ](https://www.youtube.com/watch?v=dyhIgVqbCkg)

Hope it helps.
