RealDocs

USlateBlueprintLibrary::ScreenToWidgetLocal

function UMG Blueprint Since 4.7
#include "Blueprint/SlateBlueprintLibrary.h"
Access: public Specifiers: staticUFUNCTIONBlueprintPure

Description

Converts a screen-pixel position (as obtained from OS input or GetMousePosition) into the local space of the given widget's geometry.

Caveats & Gotchas

  • Set bIncludeWindowPosition=true whenever the game runs in a window that can be moved on the desktop; in fullscreen or PIE-fullscreen the window is always at the origin and the flag has no effect.
  • The display name in Blueprints is 'ScreenToLocal', not 'ScreenToWidgetLocal'. The C++ name and the Blueprint node name differ, which can cause confusion when reading Blueprint graphs.
  • Screen pixels differ from viewport pixels on high-DPI displays — ScreenPosition from OS events may be at native resolution while the viewport renders at a lower DPI-scaled resolution. Validate which coordinate space your input source uses.

Signature

static UMG_API void ScreenToWidgetLocal(const UObject* WorldContextObject, const FGeometry& Geometry, FVector2D ScreenPosition, FVector2D& LocalCoordinate, bool bIncludeWindowPosition = false)

Parameters

Name Type Description Default
WorldContextObject const UObject* World context for viewport resolution.
Geometry const FGeometry& Geometry of the target widget.
ScreenPosition FVector2D Position in screen pixels (e.g., from GetMousePosition or a hit result ScreenPosition).
LocalCoordinate FVector2D& Output: the screen position transformed into the widget's local space.
bIncludeWindowPosition bool When true, subtracts the game window's desktop position before converting. Set to true in windowed mode to avoid an offset. false

Return Type

void

Example

Map cursor screen position into a widget for custom hit testing C++
FVector2D CursorScreenPos;
FSlateApplication::Get().GetCursorPos(CursorScreenPos);
FVector2D LocalPos;
USlateBlueprintLibrary::ScreenToWidgetLocal(
	GetWorld(),
	MyWidget->GetCachedGeometry(),
	CursorScreenPos,
	LocalPos,
	true // include window offset for windowed mode
);

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.