Using SetPawn causes Access violation

Neonzz
Sat, 20 Mar 2021 17:32:19 +0000
C++

Hello,

Here is my issue I’ve just added a Dynamic_Multicast_delegate to my code SetPawn seems to be the best method to use for the listening function however when I hit play I get Acces Violation from the PlayerController in BeginPlay() on line 13: auto AimingComponent = GetPawn()->FindComponentByClass<UTankAimingComponent>(); using dump file I see that FindComponentByClass is the method causing the unhandled exception stating this->Pawn was nullptr here is the code for SetPawn `void ATankAIController::SetPawn(APawn* InPawn)
{
Super::SetPawn(InPawn);

if (InPawn)
{
	auto PossesedTank = Cast<ATank>(InPawn);
	if (!ensure(PossesedTank)) { return; }

	PossesedTank->OnTankDeath.AddUniqueDynamic(this, &ATankPlayerController::OnPossesedTankDeath);
}

}`

11 posts - 1 participant