Get UMG Widget under mouse cursor.

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.

This is Exactly what i was looking for

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 );
}

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

Was wondering the same thing… Solved it like this:

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());
}