From 3721fff0153f5de09ce56da933acc05961b24019 Mon Sep 17 00:00:00 2001 From: PHILIP WHITE Date: Thu, 9 Nov 2023 13:13:41 +0000 Subject: [PATCH] Bugfix Regen Health Whilst Being Taking Damage --- .../EndlessVendetta/EndlessVendettaCharacter.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp index 1c677f82..98db3135 100644 --- a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp +++ b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp @@ -90,6 +90,7 @@ void AEndlessVendettaCharacter::RegenHealth() Heal(10); if (GetWorld()->GetTimerManager().GetTimerRate(RegenHealthTimerHandle) > 1.0f) { + GetWorld()->GetTimerManager().ClearTimer(RegenHealthTimerHandle); GetWorld()->GetTimerManager().SetTimer(RegenHealthTimerHandle, this, &AEndlessVendettaCharacter::RegenHealth, 1.0f, true); } if (CurrentHealth >= MaxHealth) GetWorld()->GetTimerManager().ClearTimer(RegenHealthTimerHandle); @@ -204,14 +205,12 @@ float AEndlessVendettaCharacter::TakeDamage(const float DamageAmount, FDamageEve } UE_LOG(LogTemp, Warning, TEXT("Player is dead")); UGameplayStatics::OpenLevel(this, FName(*GetWorld()->GetName()), false); - + return Super::TakeDamage(DamageAmount, DamageEvent, EventInstigator, DamageCauser); } - if (!GetWorld()->GetTimerManager().IsTimerActive(RegenHealthTimerHandle)) - { - GetWorld()->GetTimerManager().ClearTimer(RegenHealthTimerHandle); - GetWorld()->GetTimerManager().SetTimer(RegenHealthTimerHandle, this, &AEndlessVendettaCharacter::RegenHealth, 5.0f, true); - } + + GetWorld()->GetTimerManager().ClearTimer(RegenHealthTimerHandle); + GetWorld()->GetTimerManager().SetTimer(RegenHealthTimerHandle, this, &AEndlessVendettaCharacter::RegenHealth, 5.0f, true); return Super::TakeDamage(DamageAmount, DamageEvent, EventInstigator, DamageCauser); }