RealDocs

UWidgetLayoutLibrary::GetMousePositionScaledByDPI

function UMG Blueprint Since 4.7
#include "Blueprint/WidgetLayoutLibrary.h"
Access: public Specifiers: staticUFUNCTIONBlueprintPureBlueprintCosmetic

Description

Returns the player controller's mouse cursor position scaled by (1/DPI). This converts raw screen-pixel mouse coordinates into the same widget-space units used by UMG layout.

Caveats & Gotchas

  • Soft-deprecated since UE 4.17 — prefer GetMousePositionOnViewport, which is simpler and does not require a PlayerController reference.
  • Returns false when the mouse position is unavailable (cursor outside the window, or cursor hidden on some platforms).
  • The formula is MousePosition * (1 / ViewportScale). Calling GetViewportScale yourself and dividing gives identical results.

Signature

static UMG_API bool GetMousePositionScaledByDPI(const APlayerController* Player, float& LocationX, float& LocationY)

Parameters

Name Type Description Default
Player const APlayerController* The player controller whose mouse position is queried.
LocationX float& Output: the X component of the DPI-scaled cursor position.
LocationY float& Output: the Y component of the DPI-scaled cursor position.

Return Type

bool

Example

Legacy DPI-scaled mouse query C++
float X, Y;
if (UWidgetLayoutLibrary::GetMousePositionScaledByDPI(PlayerController, X, Y))
{
    FVector2D WidgetSpaceMouse(X, Y);
    // prefer UWidgetLayoutLibrary::GetMousePositionOnViewport(this) instead
}

Version History

Introduced in: 4.7

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.