How to detect mouse is over any Widget?

FWidgetPath Path = FSlateApplication::Get().LocateWindowUnderMouse(FSlateApplication::Get().GetCursorPos(), FSlateApplication::Get().GetInteractiveTopLevelWindows(), true);
TSharedPtr vp = FSlateApplication::Get().GetGameViewport();
bool overViewPort = Path.IsValid() && (Path.GetLastWidget() == vp.ToSharedRef());

You can use that bool overViewPort to check if the mouse is over the game viewport or any UI.

1 Like