# Get UMG Widget under mouse cursor.

**URL:** <https://forums.unrealengine.com/t/get-umg-widget-under-mouse-cursor/358488>\
**Category:** UI\
**Tags:** line-trace, unreal-engine, hit-event, UI, CPP, question, UMG\
**Created:** [May 25, 2016, 4:23am UTC](https://forums.unrealengine.com/t/get-umg-widget-under-mouse-cursor/358488 "2016-05-25T04:23:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rainbowdash](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Rainbowdash](https://forums.unrealengine.com/u/Rainbowdash)\
**Post date:** [May 25, 2016, 4:23am UTC](https://forums.unrealengine.com/t/get-umg-widget-under-mouse-cursor/358488/1 "2016-05-25T04:23:51Z")

</div>

Hi, im Currently trying to Get the UMG widget under the mouse cursor, with the old HUD i used functions like this

```
    GetHUD()->GetHitBoxAtCoordinates(ScreenPosition, true)

```

is there any similar way or Strategy to get the UMG Element?

thanks in advance.

---

<div class="post-metadata">

**Author:** ![Rainbowdash](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Rainbowdash](https://forums.unrealengine.com/u/Rainbowdash)\
**Post date:** [June 8, 2016, 10:49am UTC](https://forums.unrealengine.com/t/get-umg-widget-under-mouse-cursor/358488/2 "2016-06-08T10:49:45Z")

</div>

This is Exactly what i was looking for

> **[How to make UMG block left and right clicks](https://forums.unrealengine.com/showthread.php?111382-How-to-make-UMG-block-left-and-right-clicks)**
>
> Buttons, text boxes, etc. will prevent the events from firing but nothing else. Widgets have the Visibility setting but this doesn’t seem to affect anything besides the widgets that already block the mouse. I’ve tried Google but can’t find a...

---

<div class="post-metadata">

**Author:** ![Yukova](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Yukova](https://forums.unrealengine.com/u/Yukova)\
**Post date:** [December 1, 2018, 9:24am UTC](https://forums.unrealengine.com/t/get-umg-widget-under-mouse-cursor/358488/3 "2018-12-01T09:24:18Z")

</div>

For people Goolging this, also consider taking a look at FSlateApplication::LocateWindowUnderMouse

```
void ReportWidgetsUnderMouse()
{
	// Get a reference to the singleton instance of the slate application.
	FSlateApplication& MySlateApplication = FSlateApplication::Get();

	// Find a "widget tree path" of all widgets under the mouse cursor.
	// This path will contain not only the top-level widget, but all widgets underneath.
	// For example, if the mouse cursor was over a Button with a Text widget inside of it, then the last 
	// widget in the widget path would be the Text widget, and the next to last widget would be the Button widget.
	FWidgetPath WidgetsUnderCursor = MySlateApplication.LocateWindowUnderMouse( MySlateApplication.GetCursorPos(), MySlateApplication.GetInteractiveTopLevelWindows() );

	FString Result = TEXT( "" );
	if ( WidgetsUnderCursor.IsValid() )
	{
		Result += TEXT( " Count:" ) + FString::FromInt( WidgetsUnderCursor.Widgets.Num() );

		for ( int32 Idx = 0; Idx < WidgetsUnderCursor.Widgets.Num(); ++Idx )
		{
			FArrangedWidget& Widget = WidgetsUnderCursor.Widgets[Idx];

			Result += TEXT( " " ) + Widget.Widget->ToString();
		}
	}

	// Print out a quick summary of all widgets that were found under the mouse.
	UE_LOG( LogTemp, Warning, TEXT("%s"), *Result );
}

```

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_61be4d52](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_61be4d52](https://forums.unrealengine.com/u/anonymous_user_61be4d52)\
**Post date:** [February 9, 2022, 6:00pm UTC](https://forums.unrealengine.com/t/get-umg-widget-under-mouse-cursor/358488/4 "2022-02-09T18:00:34Z")

</div>

Isn’t this returning SWidgets? what if I want a reference to the UUserWidgets?

---

<div class="post-metadata">

**Author:** ![hein0r](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@hein0r](https://forums.unrealengine.com/u/hein0r)\
**Post date:** [January 9, 2024, 3:54pm UTC](https://forums.unrealengine.com/t/get-umg-widget-under-mouse-cursor/358488/5 "2024-01-09T15:54:25Z")

</div>

Was wondering the same thing… Solved it like this:

```auto
const TSharedPtr<SWidget> CurrentWidget = WidgetsUnderCursor.Widgets[WidgetIndex].Pin();
if (CurrentWidget.IsValid() && CurrentWidget->GetType() == "SObjectWidget")
{
	TSharedPtr<SObjectWidget> ObjectWidget = StaticCastSharedPtr<SObjectWidget, SWidget>(CurrentWidget);
	UserWidgetsUnderCursor.Add(ObjectWidget->GetWidgetObject());
}

```
