I am writing a medal system with a wide range of medals achieved by all different sorts of behavior.
In order to keep things decoupled I think the observer pattern fits.
So I started looking at ways to implement that in ue4.
Delegates looked like a good backbone for implementing the observer pattern to me.
However, I ran into issues with them. It looks like the observer has to have a reference to each subject.
In my case, the observer would be my Medals class.
And the subjects could be anything ideally; in order to make a robust medals system I will need to listen to all sorts of events.
So I created a single delegate with a parameter that describes what type of event it is. From there the Medals class binds to the delegate and rewards the appropriate medal when achieved.
The issue is that it looks like with delegates the observer (my medals class) needs a pointer to all of the subjects so that it can call AddDynamic to bind.
This seems to break the decoupling goal I was going for since my Medals class will need a pointer to every object that will be broadcasting the delegate.
Is there a more flexible delegate approach that I am missing?
Or does anyone know of a better way to implement this (without singleton)?