This is a fix for the bug that if you keep shooting dead pawns after you’ve already won, multiple copies of the UI will spawn, and the restart timer may reset. I noticed it straight away because I modified my UI to actively display a countdown of how many seconds were left before the game would restart. So I was seeing a ‘0’ overlaying the 5…4…3 countdown.
The fix is to early-return out of the TakeDamage() method of ShooterCharacter.cpp, if the character that’s been hit is already dead.
float AShooterCharacter::TakeDamage(float DamageAmount, FDamageEvent const& DamageEvent, AController* EventInstigator, AActor* DamageCauser) {
float damageToApply = Super::TakeDamage(DamageAmount, DamageEvent, EventInstigator, DamageCauser);
if (IsDead()) { return 0.f; }
//... rest of the function
// It's 2024. I refuse to have EVERYTHING capitalized CamelCase.
// Hence damageToApply, not DamageToApply
Without this check, every time you shoot an already-dead pawn, after the “winner” UI is on screen, all of the conditions for winning are still just as true as they were the first time you “won.” All the AIs are still dead, after all.
So multiple winner UIs spawn atop each other, and the ShooterPlayerController’s restart timer can be reset over and over again.