UUserWidget::GetOwningPlayer
#include "Blueprint/UserWidget.h"
Access: public
Specifiers: virtual
Description
Returns the APlayerController that owns this widget. Used to access the player's pawn, camera, input, or other player-specific state from within the widget.
Signature
virtual APlayerController* GetOwningPlayer() const Return Type
APlayerController* Caveats & Gotchas
- • Returns null for widgets not created with a PlayerController outer (e.g. created with a UWorld outer). Always null-check.
- • In split-screen, this returns the specific local player who owns this widget instance — useful for ensuring UI actions affect the right player.
- • A templated version GetOwningPlayer<T>() is available to cast in one call.
Example
Access the player's pawn from a widget C++
APlayerController* PC = GetOwningPlayer();
if (PC && PC->GetPawn())
{
float Health = Cast<AMyCharacter>(PC->GetPawn())->GetHealth();
HealthBar->SetPercent(Health / MaxHealth);
} See Also
Tags
Version History
Introduced in: 4.5
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?