UWidgetLayoutLibrary::ProjectWorldLocationToWidgetPosition
#include "Blueprint/WidgetLayoutLibrary.h"
Access: public
Specifiers: staticUFUNCTIONBlueprintPureBlueprintCosmetic
Description
Projects a world-space 3D location into 2D widget screen space for a specific player, accounting for DPI scaling and optional quality scaling. Use this to position HUD elements over world objects.
Caveats & Gotchas
- • Returns false when the world point is behind the camera; the output ScreenPosition is still written but should be discarded. Always check the return value before using the position.
- • ScreenPosition is already in DPI-scaled widget space — do not divide by GetViewportScale again. Using raw APlayerController::ProjectWorldLocationToScreen gives pixels, not widget units.
- • Pass bPlayerViewportRelative=true in split-screen so the position is relative to that player's sub-region, not the full screen.
Signature
static UMG_API bool ProjectWorldLocationToWidgetPosition(const APlayerController* PlayerController, FVector WorldLocation, FVector2D& ScreenPosition, bool bPlayerViewportRelative) Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| PlayerController | const APlayerController* | The player controller whose camera is used for the projection. | — |
| WorldLocation | FVector | The world-space 3D point to project. | — |
| ScreenPosition | FVector2D& | Output: the projected position in DPI-scaled widget space, with quality scaling already removed. | — |
| bPlayerViewportRelative | bool | When true, the position is relative to the player's sub-viewport region (useful in split-screen). | — |
Return Type
bool Example
Show a widget above a world actor C++
FVector2D ScreenPos;
bool bOnScreen = UWidgetLayoutLibrary::ProjectWorldLocationToWidgetPosition(
PlayerController, TargetActor->GetActorLocation(), ScreenPos, false);
if (bOnScreen)
{
MarkerWidget->SetPositionInViewport(ScreenPos);
} Tags
Version History
Introduced in: 4.7
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?