Question on Delegates

I’m fairly new to delegates so have been trying to get their behaviour clear in my mind.

In the Toon Tanks game, there are x4 Towers and x1 Player Tank, their blueprints derive from class ABasePawn and named “BP_Tower” and BP_Tank, each blueprint has attached a Health Component. The Health Component is used to dish out damage (given by the projectile class) and will eventually dispose of its Actor owner when the Damage count = 0

Projectile class:
When a projectile collides with something a hitEvent is raised , the OnComponentHit Delegate (which is bound to callback function ProjectileOnHit) broadcast the collision which ProjectileOnHit responds to and it raises a DamagEvent (UGamePlayStatics :: ApplyDamage)

Health Component Class:
Health Component implements a OnTakeAnyDamage Delegate bound to a callback function DamageTaken. The delegate listens out for event: DamageEvent (sent from Projectile class) which when received will broadcast and the bound callback function DamageTaken responds.
DamageTaken removes health from its Actor owner and will call a ActorDied function if Health =0

My question is. How does the Projectiles UGamePlayStatics :: ApplyDamage know which Actor to send the ApplyDamage event to?
Is it using the OtherActor pointer passed in from the OnComponentHit ?

This then leads to a follow up question on delegates. Is it possible for a custom event to be raised that all instances of a different class with a delegate can respond to?
E.g. I Add a Actor Light Switch to a room that a player can switch on, when on it sends a Switch On Event that can be picked up by a Actor Light delegate.
I have 5 Actor lights instances in the room and they all switch on as they are listening out for the SwitchOn event.

That is the first argument you provide is for

UGameplayStatics::ApplyDamage | Unreal Engine Documentation

Yes, that’s half of what you did with the health component. The other half would be creating the delegate and broadcasting it.

Multi-cast Delegates | Unreal Engine 4.27 Documentation

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

Privacy & Terms