I don't understand the log after the character died

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… :fearful:

Because PawnKilled is a virtual function. So when the function is invoked on a pointer or reference to the base class it will dispatch to the correct function for the concrete type of the object.

with virtual
without virtual

With virtual it dispatches to the correct function for the type of object at the address which in this case is a dog. Without virtual it just calls Animal::Speak().

Thank you for your response. Could you please confirm if I understand correctly?

In this code, this refers to the game mode. However, I have set the game mode to BP_KillEmAllGameMode and designated KillEmAllGameMode as the parent class. Therefore, the parent class of the currently designated blueprint is KillEmAllGameMode. Does this mean that the function of the child class is being called?

This means at the start of the game Unreal will create a game mode instance of type BP_KillEmAllGameMode.

Yes, as PawnKilled is a virtual function and AKillEmAllGameMode (which BP_KillEmAllGameMode is a) overrides that so that function will be called.

Now I understand. Thank you very much for informing me :grinning:

Privacy & Terms