RealDocs

UWidgetLayoutLibrary::GetViewportSize

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

Description

Returns the current size of the game viewport in pixels. This is the raw resolution before any DPI scaling is applied.

Caveats & Gotchas

  • Returns the viewport resolution in raw pixels, not DPI-scaled widget units. To work in widget space divide by GetViewportScale, or use the geometry helpers instead.
  • BlueprintCosmetic — always returns (0,0) on a dedicated server. Gate any logic on IsRunningDedicatedServer if shared code paths are involved.
  • The value can change at runtime if the user resizes the window or changes resolution; do not cache it across frames unless you handle the viewport resized event.

Signature

static UMG_API FVector2D GetViewportSize(const UObject* WorldContextObject)

Parameters

Name Type Description Default
WorldContextObject const UObject* Any UObject that provides world context; typically 'self' in Blueprint.

Return Type

FVector2D

Example

Get viewport dimensions C++
FVector2D ViewportSize = UWidgetLayoutLibrary::GetViewportSize(this);
float AspectRatio = ViewportSize.X / ViewportSize.Y;

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.