I’ve created a custom player controller. This is the .cpp
#include "MyPlayerController.h"
///////////////////////////////////////////////////////////////////////////////
// VIRTUAL PUBLIC FUNCTION //
///////////////////////////////////////////////////////////////////////////////
void AMyPlayerController::OnPossess(APawn* InPawn) {
UE_LOG(LogTemp, Warning, TEXT("My controller possess actor %s"), *(InPawn->GetName()));
}
void AMyPlayerController::PlayerTick(float DeltaTime) {
auto p = this->GetPawnOrSpectator();
if (p) {
auto loc = p->GetActorLocation();
auto ori = p->GetActorRotation();
}
Super::PlayerTick(DeltaTime);
}
I’ve associated this controller to a pawn in the editor.
When I run the game, I can see the log called by OnPossess
, and the name of the pawn is correct. But after that, when the program calls PlayerTick
method, p
is null, like the controller does not possess anything.
What I’m doing wrong, and how can I access to the pawn from the controller?