I currently came across the fact I could potentially improve my Blueprint communications by using
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 !