Add extra checking in ExplosiveActor Explode method

This commit is contained in:
baz 2023-09-18 02:59:32 +01:00
parent c944e5e6f9
commit ea06181a01
1 changed files with 10 additions and 7 deletions

View File

@ -48,14 +48,17 @@ void AExplosiveActor::Explode()
for (FOverlapResult Overlaps : outOverlaps) for (FOverlapResult Overlaps : outOverlaps)
{ {
UHealthComponent* healthComponent = Overlaps.GetActor()->GetComponentByClass<UHealthComponent>(); if (Overlaps.GetActor())
if (healthComponent)
{ {
float distance = FVector::Distance(ActorToWorld().GetLocation(), UHealthComponent* healthComponent = Overlaps.GetActor()->GetComponentByClass<UHealthComponent>();
Overlaps.GetActor()->ActorToWorld().GetLocation());
float scale = 1.f - (distance / ExplosionRadius); if (healthComponent)
healthComponent->TakeDamage(Overlaps.GetActor(), scale * MaxDamage, nullptr, nullptr, this); {
float distance = FVector::Distance(ActorToWorld().GetLocation(),
Overlaps.GetActor()->ActorToWorld().GetLocation());
float scale = 1.f - (distance / ExplosionRadius);
healthComponent->TakeDamage(Overlaps.GetActor(), scale * MaxDamage, nullptr, nullptr, this);
}
} }
} }