Get instance of MatchDispacher in MatchInit

Hello once again! :slight_smile:

Question goes: Is it possible to get an instance of MatchDispatcher in the MatchInit function? All the servers initializations goes there and some resources needs the disptacher further down the line. So, is it possible? or do i need to assign them on lets say MatchJoinAttempt where the dispacher is provided as function argument? :slight_smile:

/Gillberg

Hi @gruset.

Is it possible to get an instance of MatchDispatcher in the MatchInit function?

This is not possible. A match does not exist on the server until after the MatchInit lifecycle function has completed. In your use case if you had a MatchDispatcher it would have nowhere to send messages to because the match does not exist at that point.

or do i need to assign them on lets say MatchJoinAttempt where the dispacher is provided as function argument?

What information are you trying to send to players at match startup? There’s a great way to solve this with Nakama usually by using a basic state machine pattern to dispatch the information you need in the MatchLoop as part of the phase of the match:

Hope this helps.

Hello @novabyte and thanks for the reply!

What information are you trying to send to players at match startup?

Im not trying to send anything on match startup but rather use the dispatcher on various event listeners once the match is up and running. I solved the problem by sending the dispatcher with the event rather than giving the listeners the dispatcher. Not ideal but its works :slight_smile:

Cheers!