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:

  1. Retrieve the reference to the UGameViewportClient object:
UGameViewportClient* ViewportClient = GEngine->GameViewport;
  1. Declare a variable to store the size of the viewport:
FVector2D ViewportSize;
  1. Call the GetViewportSize() function on the ViewportClient object:
ViewportClient->GetViewportSize(ViewportSize);
  1. Access the width and height of the viewport size using the X and Y properties of the FVector2D 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.