How does the spawner get a notification of the hit of a projectile?

My actor spawns a projectile. The OnHit gets called when it hits an object. I want this projectile to be destroyed (Destroy()) but also to notify the original spawner that it hit something and possibly give it the Hit information.

How do you usually do this? A pointer to the spawner when creating the projectile that I use to call the parent? … Is there any kind of notification / observer pattern / event system you can apply here? How would you do it?

I’m using C++ exclusively.

How do you usually do this?

I am not an expert especially when it comes to best practices in C++ but still…

A pointer to the spawner when creating the projectile that I use to call the parent?

I would consider “a pointer to the spawner when creating the projectile” the best (personal opinion) available option given no additional requirements.

Is there any kind of notification / observer pattern / event system you can apply here? How would you do it?

Yes there is a delegate system but under the hood you are still exchanging pointers to the methods that need to be called.

Here is some documentation on the delegate system: Delegates and Lamba Functions in Unreal Engine | Unreal Engine 5.3 Documentation

Global events were supported (at some point) but were intentionally removed back in the day.

Ah! Cool. What about a Message System? This is used in Unity for example. You just send a message and whoever is interested will be notified.

Read through the Delegate documentation linked above and you will find Dynamic Delegates, Events and Multi-cast Delegates. How you handle your particular case is totally up to you.

Now I don’t know what Unity has as I don’t have much experience in it but there is a helpful documentation for people coming in from Unity: Unreal Engine 4 For Unity Developers | Unreal Engine Documentation
(no events though)

In the end, you can always implement yourself whatever custom communication method you need.

When I spawn a projectile I set a variable on it to indicate what spawned it. Then on the ApplyDamage function call, I put that actor in as the Instigator or Damage Causer. You can use this Instigator or Damage Causer from that point on to credit whomever caused the damage, whether you use delegates, messaging, interfaces, etc. or not. The reference is right there for you to use even just within the normal course of function calls and event handling.