Pass additional data through the damage system

Hi, I’m just going to go ahead and describe my actual problem first to explain my motives, so that any other solutions can be suggested.

Basically my end goal is damage text which groups separate instances of damage with the same “source” into a single number.

So for example if a machine gun fires bullets, and two of those bullets hit the same enemy for 5 damage each, the first bullet would show the text “5” then the second bullet would increase that text to “10”.

I can achieve this almost fine by attaching a DamageTextComponent on to each actor I want to spawn the text on and having it remember text spawned for that actor, with each text remembering the DamageCauser of the damage and grouping if the causer is the same.

Example: Machine gun fires bullets, setting the source variable of the bullets to itself. When the bullets hit, they use the source object as the DamageCauser, which makes the damage text group up as both are the same.

However a massive limitation of this is that the DamageCauser must always exist. If the source DamageCauser is destroyed, then the damage by the same source won’t group up.

Example: Machine gun fires bullets, but before the bullets hit the gun is destroyed, causing the source object on the bullets to become invalid and unable to join up with other damage from the same source.

My idea to solve this was to have each “source” object generate a unique integer to identify that source, which of course would persist after it dies.

Example: Machine gun generates a damageSourceId, and passes that to the bullets it spawns. The bullets specify this damageSourceId when applying damage, which can be read and compared by the DamageTextComponent the same way as DamageCauser would be.

Which leads me to my current problem: How can I add data to the existing damage system, through a parameter or otherwise?

I had a look at FDamageEvent, which can be derived to hold custom data, but this is data I want to add to FRadialDamageEvent and FPointDamageEvent too, which are based on FDamageEvent, all of which I want to add this functionality to.

What are my options here other than designing my own completely different damage system parallel to the existing one, or modifying the engine code?

EDIT: I solved this using an interface. Machine gun generates a unique damageSourceId and passes it to bullets that it spawns. Bullet implements IDamageSource getDamageSourceId() and returns the ID. When dealing damage, Bullet passes itself as the DamageCauser. Then on the other end of things, when receiving damage I check for the interface on the DamageCauser and call getDamageSourceId() to get the ID so that I can do what I want with it.