Hi! I wasn’t entirely convinced with the code clarity in the PawnKilled function where a cast is used to check if the pawn that was killed (passed in) was the player.
There is a built-in Pawn function called IsPlayerControlled() which seems to me like a decent way to check if the pawn that died was the player, as long as it’s called before DetachFromControllerPendingDestroy(). Is this technique fine to use?
My PawnKilled function implementation:
void AKillEmAllGameMode::PawnKilled(APawn* PawnKilled)
{
Super::PawnKilled(PawnKilled);
UE_LOG(LogTemp, Warning, TEXT("Pawn Killed!"));
if (PawnKilled->IsPlayerControlled())
{
APlayerController* PlayerController = Cast<APlayerController>(PawnKilled->GetController());
if (PlayerController != nullptr)
{
PlayerController->GameHasEnded(nullptr, false);
}
}
}