When and why would you use OnTakeAnyDamage vs Take damage override

In C++ course I saw two methods offered on doing damage. 1) Apply damage when bullet hits actor and then add multicast delegate OnTakeAnyDamage (ToonTanks). 2) Call TakeDamage on Hit Actor inside Gun and then override in on Character class (Shooter Game).
I am trying to understand in what scenarios would a programmer choose one over the other? From my current point of view they are achieving the same thing.

I also noted the difference and deduced that they were two ways of accomplishing a task, but also taught respectively two different subjects. Where in toon tanks, we spawned a projectile and bound our own functions to multicast delegates (and learned the process,) in shooter game we didn’t spawn a projectile or need to custom code the hit events. In my opinion the toon tanks version made more sense to me, but I suppose at the root of it, they’re just two ways of generating damage from hit events.

As far as scenarios where a programmer might use one over the other, I would probably want to spawn a projectile and let the physics engine work in a program that I wanted to be accurate, because otherwise you wouldn’t be able to apply things like bullet fall as easily.

Cheers,
Tele

The main difference is that in Toon Tanks it was done via a component. This allowed you to add it to any actor, consider wanting to make an explosive barrel or a wall/barrier that has health you can shoot to destroy. With the component you just add the component to the actor and call it a day.

The component allows you to have a generic yet basic mechanism for health. With overriding you are implementing specifics, say your character has armour or a shield. How would the component work with actors that don’t have those things? It would require a bit of work to have a generic health component to be able to deal with those kinds of properties.

1 Like

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

Privacy & Terms