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 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.
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.
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.