Add event to a child actor being destroyed

I’m trying to make a system where if a (spawned) child actor is destroyed, it will repeat the script that spawned it.
I’ve figured out how to spawn the first child actor, but have no idea how to set a variable or add an event to when that child actor is destroyed.

Help would be greatly appreciated!

Pictures here: Imgur: The magic of the Internet

Right click: Type Bind Event to OnDestroyed and create an event to be called when the actor is destroyed. Connect the in pin from the Bind Event node on the BeginPlay event, to create the listener as soon as possible.

I stumbled upon this question while trying to create a spawner class that is able to spawn children of an arbitrary blueprint class.

The way I went about it was to create an event in the parent, named ChildDead which does what I want (just prints “child died” in my example):

275044-spawner-childdead-event.png

Then in each child class I hardcode the overriden EventDestroyed. I get a reference to the parent using GetParentActor, cast it to the parent class and call the previously defined ChildDead parent event. GetParentActor works only in children spawned through a Child Actor Component:

275046-child-eventdestroyed.png

This approach seems acceptable for a small number of classes but gets annoying / messy quickly for an arbitrary number of them. Slightly messier if you have multiple classes of potential parents. Maybe it becomes more manageable if pulled from a blueprint library.

I wonder if it can be done cleanly by creating a custom component that is created and inserted in the child during runtime.

I think this method (delegate binding) does not do what OP asked directly in this context because unfortunately the OnDestroyed event can only accept self as an argument, i.e., the parent instead of any of its children if the event is set in the parent class.