How to get current screen size/resolution?

Viewport Size is NOT the same as Resolution

They Are Two Separate Metrics

Viewport Size relates to how much screen space the game occupies. For example, you can play a game with a resolution of 1280x720 on a 2560x1440 monitor.

When playing fullscreen for this example, you will have:

ViewportSize=2560x1440
Resolution=1280x720

This is important because (at least one my machine) UMG, text, UI elements, etc are displayed using the Viewport Size and not the Resolution in order to remain clear and crisp when playing lower-resolution games on larger monitors.

Get Viewport Size / Get Resolution

FVector2D GetGameViewportSize()
{
	FVector2D Result = FVector2D( 1, 1 );

	if ( GEngine && GEngine->GameViewport )
	{
		GEngine->GameViewport->GetViewportSize( /*out*/Result );
	}

	return Result;
}

FVector2D GetGameResolution()
{
	FVector2D Result = FVector2D( 1, 1 );

	Result.X = GSystemResolution.ResX;
	Result.Y = GSystemResolution.ResY;

	return Result;
}
11 Likes