Event Dispatchers - I thought I knew how they worked

I am trying to setup a Multiplayer System, with communication between Multiplayer Widget System, HUD and Game Instance and I am not able to get it working. I have used event dispatchers before, so thought I knew what I was doing but not understanding why what I am doing is not working.

I have a multiplayer widget system, where I have a base WBP_Multiplayer class that ALL of the widgets that are involved with the Multiplayer GUI System are children of. I also handle in the WBP_Multiplayer base class, binding all of the custom events to associated Event Dispatchers on the HUD_UI_MP blueprint.

On the Child Widgets, I then tried to override the parent events that were bound to the HUD_UI_MP event dispatcher, so that when the Dispatcher is called from the HUD_UI_MP, it should trigger the custom event bound to the dispatcher, and the child widget of parent class of MP_Multiplayer, would execute code specific to that Widget when the dispatcher is called.

I did this, so that I could make sure all the widgets have the same custom events available to them, as well as a few functions which could then be overridden in the specific widget.

I have a HUD_UI_MP blueprint that is child of HUD. This is where I handle communication between Widgets, HUD and Game Instance (GI_Multiplayer, child of GameInstance). HUD_UI_MP has all of the event dispatchers on it (ED_Login; ED_Login_Successful; ED_Disable_Login; ED_Logout; ED_Logout_Successful; ED_Disable_Login)

If I attach code directly to the event bound to event dispatcher on parent blueprint WBP_Multiplayer, it will execute that code for each instance, but if I have no code linked in parent to the event bound to event dispatcher, and then try to override parent bound event in the child widget blueprint class, no code will execute.

I have even tried calling a function in the parent widget class WBP_Multplayer from the event bound to event dispatcher, and then overriding the function in the child widget class, and no code will execute.

Should this not work like this?

I have also tried putting the event dispatchers in the WBP_Multiplayer parent class. And I have also tried putting the event dispatchers in my WBP_Sessions class which is a child class of WBP_Multiplayer, and calling the event dispatchers on the WBP_Sessions Class from the HUD_UI_MP blueprint. I have also tried casting to WBP_Multiplayer from WBP_Sessions and calling the dispatcher there and still did not work.

At this point I am dumbfounded and ready to give up. I though I had a thorough understanding of how dispatchers worked, and have used it before with great success, but like 2 years ago.

HUD_UI_MP → Show Sessions Widget (Called on HUD_UI_MP BeginPlay Event)

HUD_UI_MP → Login Custom Event Call


image

WBP_Multiplayer

WBP_Login (Child of WBP_Multiplayer)

WBP_Sessions (Child of WBP_Multiplayer)
image

Result Output

There should be a bright green print string with Worked! prnted…and nothing

I was trying to set this up so that all the widgets will update using each of their own custom code for that particular event (Disabling Login Button on WBP_Login for example, after login.

Any thoughts on this? Am I remembering how to use dispatchers incorrectly?

1 Like

your login event doesnt seem to be replicated, so your server will be calling the event but the client wont recieve it

1 Like

This is not a session nor replicated. This is just local user logging into Online Services.
After the print string says Calling ED_Login, there should be more print strings from the widgets that have events bound to the event dispatcher ED_Login.

I have switched to a Blueprint Interface that is implemented in the root class WBP_Multiplayer in which all multiplayer widgets derive from, and still, I can call the function from the blueprint interface, but only the widget connected to target will fire the event.

Hard to believe I had a good grasp on this 2 years ago, doing complex setups, and now I cant get what i would call a simple setup, to work. :frowning:

so whats calling the events and where and when? there is no reason you cant do what your trying but we cant see a lot of information so i have to guess.

its possible you call the event before the bind is set

YESSSS!, That was it, I’m so embarassaed :wink: Thank you!
At least I think it was…

Still gotta test the dispatchers…

Yes, that was it, now when I call ED_Login event dispatcher on the WBP_Sessions Widget (Child of WBP_Multiplayer), all widgets of class WBP_Multiplayer will run that Event, if I bind the event on CONSTRUCT instead of INITIALIZE

1 Like

Nope, that was not it. It will execute the code attached directly to bound event in the Parent Class, but if a child overrides the event, the override event never gets called. I also tried having the Parent Class call a Function on itself, then overriding the Function on the Child, and the overridden function will not call :frowning:

1 Like

It was half the problem. The other problem, is that overrides on events or functions will not be affected by a bind in the parent class.

I had to Bind Event to ED_Login on Construct of the Child Class specifically, in order to run code for that specific class.

It would nice nice if overrides would work; but this is still doable for me

hmm that should work, ive done it myself.

i guess you could put the bindings in a function and call the function on child BPs so they manually bind

1 Like

Yes, I thought so as well, and since you were of the same opinion I wiped all and redid and got it to work. TL;DR

  • Was binding dispatchers before object was available to bind to;
  • had binding setup incorrectly - I was calling the ED_Dispatcher from a different object through the object that had the dispatcher. I changed this so that the Object would first call a custom event on the object that has the event dispatcher, then that custom event calls the event dispatcher on itself (I have not confirmed this is required?)

This is my setup now:
WBP_Multiplayer = Base Class for all Mulitplayer UI Widgets
HUD_UI_MP → Handles Communication between game instance and UI MP Widgets
GI_Multiplayer → Handles Multiplayer Events

HUD_UI_MP creates the Sessions Widget, so it Holds and Sets its reference to the WBP_Sessions widget, all other widgets can access the HUD via player controllers. Therefore, any WBP_Multiplayer widget is able to call events from HUD, and HUD then calls events on Parent Widget, and Parent Widget calls Event Dispatcher for all other widgets to execute event.


It is also possible to call the Event Dispatcher Directly from the Blueprint that has it, such as this

WBP_Multiplayer Binds the Class Event to the Event Dispatcher (During CONSTRUCT, so that all child widgets will be initialized when parent widget calls construct (ChildWidgets fire events first before parent, parent comes last)

WBP_Sessions is a Child of WBP_Multiplayer; Contains all UI elements for Multiplayer Sessions (Logins, Errors, Host, Find Sessiosn ect.) and has the Event Dispatchers. Event Init Login is from the Parent Class and calls parent

All the widget elements in WBP_Sessions, derive from WBP_Multiplayer, and are able to run the event when called from event dispatcher



Hope this helps someone, this makes things sooooooooo much easire for updating the Sessions Widget depending on the situation, as I can just call dispatcher for tat situation, and each widget handles it as needed. Huge time saver!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.