How to listen for changes on parent actor?

I made a weapon that’s basically a sticky grenade launcher. If it hits a Character, then the grenade attaches itself to the Character.

I got it working, except for one detail: if the character dies, any attached grenade keeps floating in the air. How can I solve this problem?

I thought about adding an “event listener” on the attached character, which would trigger an event on the projectile blueprint if the character dies. I just can’t figure out how to do that. But other ideas are welcome as well.

Note: the Character, Weapon, and Projectile are all class blueprints, so changes could be implemented on either of them.

Details: The attachment itself is made on the Weapon, because it’s an instant hit (trace) weapon. A projectile (AShooterProjectile) blueprint is spawned on the hit location, and if the trace returned a Character as its HitActor, then an attachment is made on the newly spawned grenade.

There’s probably many ways to handle this, but my idea:

#Method 1

make a blueprint of your grenade

spawn the blueprint instead of the baseclass.

make a variable ParentActor on the grenade

when grenade is spawned and attached, set this variable to the Character

In the GRENADE’s event graph

add an Event Tick,

and every tick

do a check

if the Parent’s health or whatever is too low or it died, grenade should remove itself

#Method 2 (more efficient)

in character blueprints there are great functions like event receive damage that you can use

and you could create an array of all attached grenades on your character

and when grenade is spawned, it could add itself to the Character’s grenade array

then when character takes damage, check if need to loop through all attached grenades and remove them

I am inclined to think that the second method is better performance wise, because you are not checking every tick, you are only checking when damage is received.

Also, only the character is checking its own health, rather than multiple grenades checking the character’s health, all doing the same calculation

I left both methods in this post to demonstrate why method 2 is so much better :slight_smile:



Ahh, great idea, thanks Rama!

I’ve succesfully implemented the second method, it’s all working now. :slight_smile: