APlayerController::Possess
#include "GameFramework/Controller.h"
Access: public
Specifiers: virtual
Description
Commands this controller to take control of the given pawn, calling `OnPossess` and triggering the pawn's `PossessedBy` callback. Any previously possessed pawn is automatically unpossessed first. Override `OnPossess` (not `Possess`) to add custom logic.
Signature
virtual void Possess(APawn* InPawn) final Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| InPawn | APawn* | The pawn to take control of. | — |
Return Type
void Caveats & Gotchas
- • `Possess` has been `final` since UE 4.22 — override `OnPossess` instead.
- • Only effective on the server in networked games; calling it on a client has no effect.
- • If the target pawn is already possessed by another controller, that controller unpossesses it first.
Examples
Server-side possession during respawn C++
void AMyGameMode::RespawnPlayer(APlayerController* PC)
{
APawn* NewPawn = GetWorld()->SpawnActor<AMyPawn>(DefaultPawnClass, SpawnTransform);
PC->Possess(NewPawn);
} Override the possession hook C++
void AMyPlayerController::OnPossess(APawn* aPawn)
{
Super::OnPossess(aPawn);
// Custom init here
} Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
| 5.0 | stable | — |
Feedback
Was this helpful?