UWidgetLayoutLibrary::GetMousePositionOnViewport
#include "Blueprint/WidgetLayoutLibrary.h"
Access: public
Specifiers: staticUFUNCTIONBlueprintCallable
Description
Returns the current mouse cursor position in the local coordinate space of the viewport widget. The position is already in DPI-scaled widget units and does not need further conversion for use with UMG layout.
Caveats & Gotchas
- • Returns (0,0) on platforms with no mouse cursor (consoles, mobile). Check platform capabilities before relying on this value.
- • This is the preferred replacement for the deprecated GetMousePositionScaledByDPI — use it instead unless you specifically need the player-relative variant.
- • The position is in the viewport's local space, not screen pixels. Adding it directly to a SetPositionInViewport call will place a widget exactly under the cursor.
Signature
static UMG_API FVector2D GetMousePositionOnViewport(const UObject* WorldContextObject) Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| WorldContextObject | const UObject* | Any UObject that provides world context. | — |
Return Type
FVector2D Example
Place a tooltip widget at the mouse cursor C++
FVector2D MousePos = UWidgetLayoutLibrary::GetMousePositionOnViewport(this);
TooltipWidget->SetPositionInViewport(MousePos, false); See Also
Tags
Version History
Introduced in: 4.17
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?