Class-independent event dispatcher?

Event dispatchers are essential for an event-driven approach, but their dependency on classes can sometimes be quite difficult to use. Is there an event dispatcher that is implemented like an interface and can be used by all classes?
In principle, I think it’s the same as an interface. But, instead of being actively executed like an event, they are passively executed by being tied to an event.

you can do this in c++ the trick is you need to know the signature

or you can use an actor component/manager class as proxy, its still a hard ref but to a lightweight class

or finally check out the GameplayMessageSubsystem

1 Like

Gameplay Message Subsystem is interesting. If I had known about it sooner, I would have incorporated it into the entire system, but unfortunately, development was already quite advanced.
I’m worried about the limited search results, but I’ll dig a little deeper and see if I can use it partially.

For now, the best solution might be to use the Actor component. However, it still seems like it would be a lot of work to have a single component recognize completely different classes.

the component doesn’t need to, its just a proxy.

So the owner calls an event on the component, lets say HealthChanged, and a widget can bind to the component without knowing about the owner.

or you can call GenericEvents with GameplayTags.

you can make GenericEvents with payloads (UObject or FInstancedStruct) for dynamic data

Even if i use it as a proxy, don’t you still need to make the component aware of the actor? All information still resides with the actor.
If i implement all shared variables in the component, it is possible to cut off the owner and external references. But that would mean rethinking the design from the ground up.

I don’t know about Generic Events. Is this possible to do in blueprint? There are many interesting features, but BP seems to have been put on the back burner.

not exactly, the actor is the ‘Owner’ so you have a ref to it but its generic so not a hard ref

this means you could GetOwner()→UseInterface/Cast but that kinda defeats the purpose, usually youd just pass through whatever info on the dispatcher itself, so OnHealthChanged passes through a float.

you can create one, so say an event dispatched passes through a Tag and UObject, the Tag describles the payload and then you can SwitchOnTag then cast/interface to get your data from the object

Sorry, this is the first time I’ve heard of these approaches, so I can’t really picture them.

Binding to an event dispatcher requires an explicit reference. But from what you’ve said, does that mean that an actor component can execute actor events without being cast to an actor? I know Owner isn’t a explicit reference, but if it was, it probably wouldn’t be possible to get anything from Actor.

To send variables from an actor through an interface, the actor needs to know the interface holder. If an interface holder issues an event to an actor, it will not be event-driven.

dont worry i went through the same, thats why i came up with these systems.

it can actually, EventDispatchers in an actor component can be bound to by the owner automatically.

But we may not be talking about the same thing. If you just want to call a function then you can use an interface, if you want to listen for an event then use the actorcomponent with an ED

Lot of different people have published something like this. There are quite a few on FAB, there’s the Gameplay Message system from Lyra that Auran mentioned and lots of people have published versions just on GitHub for free. Including me :smiley:

You don’t have to switch your whole game over at one time. You can add an event system, create new things using it and slowly transition other systems over as you do work on them.