UGameplayStatics::GetViewProjectionMatrix
#include "Kismet/GameplayStatics.h"
Access: public
Specifiers: staticBlueprintPure
Description
Computes the View, Projection, and combined ViewProjection matrices for a given FMinimalViewInfo. Use this when you need to manually project world-space positions into screen-space or perform custom frustum calculations.
Caveats & Gotchas
- • The resulting ProjectionMatrix uses a reversed-Z depth convention on platforms that support it (most modern hardware under DX12/Vulkan). If you compare depth values computed here against raw hardware depth buffers, account for the reversal.
- • FMinimalViewInfo must have a valid AspectRatio set; passing 0 causes a divide-by-zero inside the projection matrix calculation and produces a degenerate matrix.
Signature
static ENGINE_API void GetViewProjectionMatrix(FMinimalViewInfo DesiredView, FMatrix &ViewMatrix, FMatrix &ProjectionMatrix, FMatrix &ViewProjectionMatrix); Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| DesiredView | FMinimalViewInfo | Camera view info struct to compute matrices from. | — |
| ViewMatrix | FMatrix & | Output view matrix (camera transform inverted into view space). | — |
| ProjectionMatrix | FMatrix & | Output projection matrix derived from the FOV and aspect ratio in DesiredView. | — |
| ViewProjectionMatrix | FMatrix & | Output combined View * Projection matrix. | — |
Return Type
void Example
Project a world point to screen using the computed VP matrix C++
FMinimalViewInfo ViewInfo;
PlayerCameraManager->GetCameraViewPoint(ViewInfo.Location, ViewInfo.Rotation);
ViewInfo.FOV = 90.f;
ViewInfo.AspectRatio = Viewport->GetDesiredAspectRatio();
ViewInfo.ProjectionMode = ECameraProjectionMode::Perspective;
FMatrix View, Proj, VP;
UGameplayStatics::GetViewProjectionMatrix(ViewInfo, View, Proj, VP);
FVector4 ClipPos = VP.TransformFVector4(FVector4(WorldPos, 1.f));
if (ClipPos.W > 0.f)
{
float ScreenX = (ClipPos.X / ClipPos.W + 1.f) * 0.5f;
float ScreenY = (1.f - ClipPos.Y / ClipPos.W) * 0.5f;
} Tags
Version History
Introduced in: 4.14
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?