UWidgetLayoutLibrary::GetMousePositionOnPlatform
#include "Blueprint/WidgetLayoutLibrary.h"
Access: public
Specifiers: staticUFUNCTIONBlueprintCallable
Description
Returns the platform mouse cursor position in absolute desktop coordinates, independent of the game window. Use this when you need the raw OS-level cursor position, for example to position OS-native windows relative to the cursor.
Caveats & Gotchas
- • This is an absolute desktop position, not a viewport-relative position. Subtract the game window's top-left corner if you need to convert to viewport space.
- • In windowed mode, the desktop coordinates include the position of the game window itself on the monitor — do not use this for in-game HUD placement.
- • Returns (0,0) on platforms that have no platform mouse concept (some consoles). Use GetMousePositionOnViewport for cross-platform in-game cursor needs.
Signature
static UMG_API FVector2D GetMousePositionOnPlatform() Return Type
FVector2D Example
Read absolute desktop mouse position C++
FVector2D DesktopMousePos = UWidgetLayoutLibrary::GetMousePositionOnPlatform();
// Convert to window-relative by subtracting the window position
FVector2D WindowPos;
GEngine->GameViewport->GetWindow()->GetPositionInScreen(WindowPos);
FVector2D ViewportRelative = DesktopMousePos - WindowPos; Tags
Version History
Introduced in: 4.17
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?