Basically happends when you spam the Shoot button and if for some reason the AShooterCharacter::TakeDamage method enters when the character is dead it would crash unreal engine because our statements
if (IsDead())
{
DetachFromControllerPendingDestroy();
GetCapsuleComponent()->SetCollisionEnabled(ECollisionEnabled::NoCollision);
}
So I added an contition at the very first of the TakeDamage method so easily get rid of that problem.
if(IsDead()) return 0.0f;
this is the full method:
float AShooterCharacter::TakeDamage(float DamageAmount, FDamageEvent const& DamageEvent, AController* EventInstigator, AActor* DamageCauser)
{
if(IsDead()) return 0.0f;
float DamageToApply = Super::TakeDamage(DamageAmount, DamageEvent, EventInstigator, DamageCauser);
DamageToApply = FMath::Min(Health, DamageToApply);
Health -= DamageToApply;
UE_LOG(LogTemp, Warning, TEXT("%s received damage! %f health remaining"), *GetOwner()->GetName(), Health);
if (IsDead())
{
DetachFromControllerPendingDestroy();
GetCapsuleComponent()->SetCollisionEnabled(ECollisionEnabled::NoCollision);
}
return DamageToApply;
}