UGameplayStatics::ProjectWorldToScreen
#include "Kismet/GameplayStatics.h"
Access: public
Specifiers: staticBlueprintPure
Description
Projects a 3D world-space position onto the player's screen, returning the 2D pixel coordinate. Use for placing screen-space UI elements (health bars, waypoint markers) above world actors.
Caveats & Gotchas
- • Returns false when the world position is behind the camera, but ScreenPosition may still contain an extrapolated off-screen value; always check the return value before using it for UI placement.
- • In split-screen, coordinates are in full-screen pixel space by default; pass bPlayerViewportRelative=true to get coordinates relative to the player's sub-region for correct widget positioning.
- • The projected position does not account for widget anchoring or DPI scaling; divide by viewport size to convert to 0-1 UV space if needed by your UI system.
Signature
static ENGINE_API bool ProjectWorldToScreen(APlayerController const* Player, const FVector& WorldPosition, FVector2D& ScreenPosition, bool bPlayerViewportRelative = false); Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| Player | APlayerController const* | The player controller whose camera is used for projection. | — |
| WorldPosition | const FVector& | The world-space position to project onto the screen. | — |
| ScreenPosition | FVector2D& | Output: 2D screen-space pixel coordinate. | — |
| bPlayerViewportRelative | bool | If true, the result is relative to the player's sub-viewport rather than the full screen; useful for split-screen widget placement. | false |
Return Type
bool Example
Place a health bar widget above an enemy C++
FVector2D ScreenPos;
if (UGameplayStatics::ProjectWorldToScreen(
PlayerController,
Enemy->GetActorLocation() + FVector(0, 0, 100.f),
ScreenPos))
{
HealthBarWidget->SetPositionInViewport(ScreenPos);
HealthBarWidget->SetVisibility(ESlateVisibility::HitTestInvisible);
}
else
{
HealthBarWidget->SetVisibility(ESlateVisibility::Hidden);
} Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?