Unable to get onTakeAnydamage to fire

The Project is created from a basic Third person preset
I have created a bomb class and bp deriving from it.
I have placed a default - BP_ThirdPerson player on the map, and trying to get it to damage by throwing bombs at it. and unable to do so using the ApplyRadialDamageWithFalloff. I have attached the relevant code




The Debug Sphere is the explosion radius, which ive set large to make sure it hits the character.
Edit:

  1. I have already enabled “can take damage”

What’s the owner of the character? As that is what you’re adding binding to. With that said it would make more sense to override TakeDamage.

Hi DanM Thanks for the response.

This Character Which i have shared on the screenshot is just a Drag Dropped version of the BP_ThirdPerson Character which we get and not the player pawn, So i would assume the Owner is an AIController? (if im not wrong? pls correct me).

Could you please elaborate the second part, What it means to override the TakeDamage? (Im Sorry, im fairly new to this and still getting the hang of it, and i apologise if its a very basic question

Please let me know if you want me to include additional codes. i would gladly share!

Is the controller what gets hit? If you remove GetOwner()-> from that line it will probably work as expected.

However, what broadcasts that delegate is AActor::TakeDamage which you can just override instead of having this level of indirection (TakeDamage → Broadcast Delegate → call your function)

class AMyCharacter : ...
{
public:
    virtual float TakeDamage(float DamageAmount, const FDamageEvent& DamageEvent, AController* EventInstigator, AActor* DamageCauser) override;
};

float AMyCharacter::TakeDamage(float DamageAmount, const FDamageEvent& DamageEvent, AController* EventInstigator, AActor* DamageCauser)
{
    float Damage = Super::TakeDamage(DamageAmount, DamageEvent, EventInstigator, DamageCauser);
    // do stuff
    return Damage;
}

Oh My God! Thank you so so much!
Removing the GetOwner() Fixed it. Only after you pointed it out i realised, its not the Controller which is taking damage!

As for your second point, I understand AActor::TakeDamage() can be called straight away for my damage logic. And it absolutely makes sense. But is there any Advantages or Specific use case why i would need this indirection? (I kind of drew this pattern of taking dmg from the ToonTanks lecture)

When the event isn’t on itself. Like the health component was to the tank/turrets. If you coded that functionality within ABasePawn you could just override TakeDamage.

The point of the health component was to be a reusable generic component so you could add it to any actor you wanted to add damage.

Thank you So much!
It’s perfectly clear to me now! Since the Health Component is managing the health state of the actor, We are adding a delegate to the OnTakeDamage of the Owner and pass in the reference of the dmg logic function (which resides in health component) .

So in my Scenario here, where im writing the dmg logic on the Actor Itself, i can simply override the TakeDamage function and use it for my dmg logic.

Thank you so much again!

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

Privacy & Terms