ue4 get size of viewport c++
To get the size of the viewport in C++ within the Unreal Engine 4 (UE4) framework, you can use the GetViewportSize()
function. Here are the steps to do so:
- Retrieve the reference to the
UGameViewportClient
object:
UGameViewportClient* ViewportClient = GEngine->GameViewport;
- Declare a variable to store the size of the viewport:
FVector2D ViewportSize;
- Call the
GetViewportSize()
function on theViewportClient
object:
ViewportClient->GetViewportSize(ViewportSize);
- Access the width and height of the viewport size using the
X
andY
properties of theFVector2D
object:
int32 Width = ViewportSize.X;
int32 Height = ViewportSize.Y;
Now, you can use the Width
and Height
variables to perform further operations or display the size of the viewport as needed.
Here's the complete code snippet:
UGameViewportClient* ViewportClient = GEngine->GameViewport;
FVector2D ViewportSize;
ViewportClient->GetViewportSize(ViewportSize);
int32 Width = ViewportSize.X;
int32 Height = ViewportSize.Y;
By following these steps, you can obtain the size of the viewport in C++ within the Unreal Engine 4 framework.