Event dispatcher shared by multiple classes

MaterWelon.-
Sat, 16 Mar 2024 23:37:07 +0000
Programming & Scripting

Hey there!
So, I was implementing a constructor system, where the player puts an object in a machine, and it transforms it into something else. A bit like in satisfactory, except that there is no interface, you literraly put something in and it comes out the other side after some time.

I wanted to make a system that would store the crafted item, only spitting one, untill the player picks it up.
When the player picks the item from the crafter, if there is any more in the storage, the other one will come out.

To do that, I thought of using event dispatchers. Since all craftable items are pickable, I have 2 interfaces (one for pickable and one for craftable) that includes functions for those object.

Among them, I already have a “picked up” event, so the idea was to call an event dispatcher after that, and listen to it on the constructor (since I have the reference to the spawned object).

However, it seems that to bind to a certain event dispatcher, I need a reference to the specific class that implements said event. while, idealy, I could have called “on picked up” from any class that implements the pickable interface.

Is there a way to do it?
Inside my consctructor bp:

Exemple of implementation of the picked up function from the pickable class

4 posts - 2 participants