Taking damage

Couple questions:

  • Should we really return the capped damage (i.e. result of FMath::Min) as done in the lesson, or the original amount? The parent class said it used that original amount. It doesn’t seem correct to later tell that less was used from the hit.
    For that matter, the TakeDamage function in APawn has a comment saying to not modify the amount after calling Super::TakeDamage:
float APawn::TakeDamage(...)
{
    ...
	// do not modify damage parameters after this
	const float ActualDamage = Super::TakeDamage(Damage, DamageEvent, EventInstigator, DamageCauser);
    ...
}

Moreover, AActor has already broadcast that the original amount was applied:

float AActor::TakeDamage(...)
{
    ...
    ReceivePointDamage(ActualDamage, ...);
    OnTakePointDamage.Broadcast(this, ActualDamage, ...);
    ...
}
  • Shouldn’t we apply the damage via InternalTakePointDamage instead of TakeDamage, that seemed to be the function that actually decides how much of the damage is being applied.
    I think it is also necessary to handle layered damages (e.g. energy shield → armor → health), where the function could do something like:
float InternalTakePointDamage(float Damage, ...) {
    float MyLayerDamage = FMath::Min(Damage, MyLayerHealth);
    MyLayerHealth -= MyLayerDamage;
    float LeftOverDamage = Damage - MyLayerDamage;
    float InnerLayersDamage = Super::InternalTakePointDamage(LeftOverDamage, ...);
    return InnerLayersDamage + MyLayerDamage;
}
  • Shouldn’t we use FMath::Clamp instead of FMath::Min since the amount can be negative? I saw an example, I believe it was the Epic website but I can’t find it again, where health kits work by applying negative damage.

I think it’s hard to say exactly how this is supposed to be done as the documentation for this is practically non-existent; you’re pretty much just left to draw conclusions from code as you have done.

Your example for InternalTakePointDamage looks like you could do the same thing in TakeDamage. I imagine InternalTakePointDamage is intended for things that would effect the damage to be applied e.g. bullet type, headshot, distance.

RE: FMath::Clamp. If you aren’t going to have healing weapons/items then I don’t think it matters. It’s your game and you know what it has. If you want healing then negative damage is a sensible way to do that IMO.

It doesn’t look to me (and thus why I asked the question) that it can be done with TakeDamage (well, not without some drawbacks) because of what it does do (broadcasting events and such). TakeDamage either doesn’t know what you did (if you handle the damage before calling Super::TakeDamage), or it doesn’t know what you will do (if you handle the damage after calling the parent).

If the damage is a all-or-nothing deal, as in the lesson, then TakeDamage works. But that’s a bit of a narrow usage for a lesson trying to teach Unreal Engine.

I agree though that without a proper documentation from Epic, it’s hard to know what is the proper way of doing something, or even if there is a proper way. But insight from experts is part of the reasons to take courses.

… If that were true, bugs wouldn’t exist.
And even if this was true, this is a code example, this is a lesson. This video is to teach others how to write their own projects, and you don’t know what their games have and do. You should be showing the proper way, the generic way. :frowning:

1 Like

I think I misunderstood the design of your example (also not paying close enough attention - sorry). Your proposed system of layered health where it’s invulnerability would be what I was referring to

My envisioned design and what I thought you were saying was where you would just have additional health - like armour - that you take a way; that’s not going to effect the actual damage that was dealt unlike an invulnerability.

I guess, in the end, it depends on how Unreal is used. Like, if a pawn is invincible, should TakeDamage pretend that “no damage was taken” (i.e. cancel the damage event), or should it say that “damage was taken but without effect” (the damage event still has 100% of the damage, but “ActualDamage” is zero)?

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms