UWidgetLayoutLibrary::GetViewportScale
#include "Blueprint/WidgetLayoutLibrary.h"
Access: public
Specifiers: staticUFUNCTIONBlueprintPureBlueprintCosmetic
Description
Returns the DPI scale factor currently applied to the game viewport. Widget positions and sizes in UMG are expressed in virtual units equal to logical pixels at scale 1.0; multiply raw screen pixels by (1/scale) to convert.
Caveats & Gotchas
- • BlueprintCosmetic — returns 1.0 on dedicated servers. Never use this value to drive gameplay logic.
- • The scale comes from the DPI Scaling Curve set in Project Settings > User Interface. If no curve is set, this returns 1.0 regardless of resolution.
- • Caching this value across frames can cause subtle layout bugs when the viewport is resized mid-session. Prefer querying it fresh when reacting to a viewport resize.
Signature
static UMG_API float GetViewportScale(const UObject* WorldContextObject) Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| WorldContextObject | const UObject* | Any UObject that provides world context. | — |
Return Type
float Example
Convert raw mouse position to widget space C++
float Scale = UWidgetLayoutLibrary::GetViewportScale(this);
FVector2D RawMousePos; // obtained from some input event
FVector2D WidgetSpacePos = RawMousePos / Scale; Tags
Version History
Introduced in: 4.7
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?