Skip to content

Instantly share code, notes, and snippets.

@sephirot47
Created June 30, 2015 14:32
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sephirot47/8e475b090d4314b6a628 to your computer and use it in GitHub Desktop.
Save sephirot47/8e475b090d4314b6a628 to your computer and use it in GitHub Desktop.
UE4 Get Viewport / Screen Size and Center
/*
IMPORTANT!
In order to be able to use this functions, in the file "YourProject.h" change this:
#include "EngineMinimal.h"
For this:
#include "Engine.h"
*/
//Viewport Size
const FVector2D ViewportSize = FVector2D(GEngine->GameViewport->Viewport->GetSizeXY());
//Viewport Center!
const FVector2D ViewportCenter = FVector2D(ViewportSize.X/2, ViewportSize.Y/2);
@benbyy
Copy link

benbyy commented Feb 14, 2020

Thanks! Just what I needed.

@AndrewWoodworth
Copy link

Thank you, this was still helpful 5 years later.

@connorjak
Copy link

A little more specific (maybe better include-what-you-use for better build times?): #include "Engine/Engine.h"

@YesIDont
Copy link

Another way to do it is like this:
const FVector2D ViewportSize = FVector2D(GEngine->GameUserSettings->GetLastConfirmedScreenResolution());

@Nikki-Old
Copy link

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment