How do I initialise an FRadialDamageEvent?

I am trying to deal radial damage to nearby pawns, but I’m having trouble figuring out how to create my FRadialDamageEvent struct properly. I have the following code which calls TakeDamage():

FRadialDamageEvent DamageDetails;
DamageDetails.Origin = this->GetActorLocation();
DamageDetails.Params.InnerRadius = 100.f;
DamageDetails.Params.OuterRadius = 400.f;
DamageDetails.Params.BaseDamage = 500.f;
DamageDetails.Params.DamageFalloff = 1.f;
Opponent->TakeDamage(2.f, DamageDetails, GetController(), EquippedWeapon);

In my character class I have a TakeDamage override which does this:

float fDamageToApply = Super::TakeDamage(DamageAmount, DamageEvent, EventInstigator, DamageCauser);
FString szApplied = FString::Printf(TEXT("OUCH! Damage applied: %f"), fDamageToApply);
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, szApplied);
return fDamageToApply;

But the value of fDamageToApply is always 0. I’m not sure what values I’m meant to supply. Does anyone have a code snip I could look at?

Usually the damage returned by Super::TakeDamage is the same passed on DamageAmount, but if you have TakeDamage overrides on the parent classes of that class it’s safer to use what you’re doing. Anyway, i would suggest debugging and stepping into the Super::TakeDamage function to figure out why 2.f as a parameters somewhere along the way became 0.

Yeah, I was hoping to avoid that. I’m not building from source so I don’t have the engine code to debug through, but it looks like I’m going to have to.

Just try with different values or try using FPointDamageEvent to see if the return value is still different from the one you pass as a parameter to try to narrow it down.

I spent a whole afternoon doing just that, but got no joy :frowning:

Ok, so I figured out what was wrong. I stumbled across the function UGameplayStatics::ApplyRadialDamageWithFalloff(…) which shows how to form the request properly and you need to fill out a field in the struct which contains all the component hits. Based on everything I’d read, I assumed that the fact you are calling Opponent->TakeDamage() you did not need to supply this, but you do.

1 Like