UGameplayStatics::GetPlayerCharacter
#include "Kismet/GameplayStatics.h"
Access: public
Specifiers: static
Description
Returns the ACharacter possessed by the given local player controller, or null if the controller has no pawn or the pawn is not an ACharacter.
Signature
static ENGINE_API ACharacter* GetPlayerCharacter(const UObject* WorldContextObject, int32 PlayerIndex) Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| WorldContextObject | const UObject* | Any valid UObject in the world. | — |
| PlayerIndex | int32 | Zero-based local player index. | — |
Return Type
ACharacter* Caveats & Gotchas
- • Returns null if the player's pawn is not an ACharacter subclass — e.g. if the player possesses a vehicle or a plain APawn.
- • Cast the result to your project's character class before accessing project-specific properties: Cast<AMyCharacter>(UGameplayStatics::GetPlayerCharacter(this, 0)).
Example
Access the player character and its health C++
AMyCharacter* Player = Cast<AMyCharacter>(
UGameplayStatics::GetPlayerCharacter(this, 0)
);
if (IsValid(Player))
{
Player->ApplyHeal(50.0f);
} Tags
Version History
Introduced in: unknown
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?