Global EventDispatchers in GameInstance

Hi everybody,

I currently came across the fact I could potentially improve my Blueprint communications by using Event Dispatchers.

Some context :

However, my case is a bit special as I don’t have 1 sender and multiple receivers, but multiple senders and multiple receivers. Each and every sender has its own Event Dispatchers but they all have the “same ones” (hope what I say is understandable). That means the receivers need to somehow receive the references of all the senders and Bind the “same” Event for each of these senders multiple times.

You can see that it is a completely impractical way of working. I came across a first solution which uses a separate Blueprint Class to store all the EventDispatchers (would be like an “Event Dispatcher Library” of some sort). That means all the senders Call the same Events and the receivers only need to Bind an Event once. This is already a huge improvement, but now the receivers and the senders need to receive a reference to this “Event Dispatcher Library” instance.

However, some of my senders are User Widgets. It means that unlike Actors in the scene, their instances don’t exist until the execution. It then means that I cannot give them a reference to the “Event Dispatcher Library” instance from the Editor, but has to be done through Blueprints. I could certainly use the “Get Actor of Class” at Event Construct to retrieve the reference of the instance. But this node is marked as “slow” and I certainly would prefer to avoid using it.

My question :

After a few researches, I came across the existence of “GameInstance”. From what I understood, this is mostly used to save certain informations (like the character health) so they don’t get lost when changing Levels. But the GameInstance is also global, so accessible everywhere. And I can use it to make “Global” EventDispatchers that all my senders and receivers can access very easily. I tried and it works like a charm.

But is it a good idea ? Would I be making a mistake because there are things I don’t quite take in consideration or can I use the GameInstance that way ? Would love to hear what you guys think.

Thanks a lot in advance !

It would work OK if there’s no other way of moving data across. The method you mention is described here:

In this very case as a way to push data into the Level Blueprint as it’s notoriously annoying to do so. But yes, you could treat the GI as a dispatcher manager. It would receive calls and propagate data to whoever else needs it.

This way you get a less tight actor coupling - those actors really do not need to know about each other’s existence. They just talk / listen to the Game Instance… from anywhere.

On the other hand, I’ve yet to run into a non-Level Blueprint scenario that would render such undertaking unavoidable. But depending on the mechanics and how / when actors come into play, it may be necessary / more logical to do so, ofc.

This will become a wiring nightmare at some point so do note that this exists:

…and can be used inside a function. Besides that, it’s somewhat uncommon knowledge but Event Dispatchers can also bind directly to functions.

Another possibility is something like:

Global dispatchers are do-able.

Very interesting informations ! I’ll make sure to use the Create Event when needed. Thanks a lot !