float AShooterCharacter::TakeDamage(float DamageAmount, struct FDamageEvent const &DamageEvent, class AController *EventInstigator, AActor *DamageCauser)
{
float DamageToApply = Super::TakeDamage(DamageAmount, DamageEvent, EventInstigator, DamageCauser);
DamageToApply = FMath::Min(Health, DamageToApply);
Health -= DamageToApply;
UE_LOG(LogTemp, Warning, TEXT("Health: %f"), Health);
if (IsDead())
{
DetachFromControllerPendingDestroy();
GetCapsuleComponent()->SetCollisionEnabled(ECollisionEnabled::NoCollision);
ASimpleShooterGameModeBase* GameMode = GetWorld()->GetAuthGameMode<ASimpleShooterGameModeBase>();
if (GameMode != nullptr)
{
GameMode->PawnKilled(this);
}
}
return DamageToApply;
}
void ASimpleShooterGameModeBase::PawnKilled(APawn* PawnKilled)
{
}
void AKillEmAllGameMode::PawnKilled(APawn* PawnKilled)
{
Super::PawnKilled(PawnKilled);
UE_LOG(LogTemp, Warning, TEXT("Pawn has been killed!"));
}
If you run the game and the character dies, the log will pop up. Logs that you’re dead.
But I think AShooterCharacter called the function of SimpleShooterGameModeBase, but I don’t know how the function of the child class AKillEmAllGameMod was called…