C++ Pawn Possession

Is there a way to possess a pawn like this

but in c++ code, because so far when i type “unreal engine 4 c++ possession” all that comes up is blueprints

Here is the particular function in the docs: AController::Possess | Unreal Engine Documentation

This function occurs on the controller, so first you’ll want to get the particular character controller then call this function on it with whatever pawn you are switching to (it will unpossess automatically).

Possesing a new pawn would require the following steps:

  • Cache a reference to your current pawn
  • Unposses your current pawn (Controller->UnPossess())
  • Spawn the new pawn using a different class
  • Posses the new pawn (Controller->Possess(NewPawn))
  • If all went well destroy the cached pawn, if not you could always re-posses the old one.



You should not forget to cache your player controller too

APlayerController* controller = GetController();
ACharacter* character = GetWorld()->SpawnActor...

otherwise GetController() from unpossessed pawn will return null

1 Like

what includes please ?