The best practice is for Unreal Dedicated Server to notify Nakama game end

I want to ask what the best practice is for Unreal Dedicated Server to notify Nakama after a game ends. Should we use an RPC to notify Nakama that a game has ended, or should the Dedicated Server use RealtimeClient to notify Nakama?
I have found that we cannot modify the state of a match through an RPC.we can only modify the state of a match by sending a message through a websocket and modifying the state through HandleOpMessage."

It’s difficult to answer this as it entirely depends on your setup. An RPC would certainly be one way to provide Nakama with the results of the game. I would not advise trying to influence the internal state of a Nakama match from an external source.

If you want to provide Nakama with details of a winning player for example, you can achieve this by calling an RPC on Nakama using a server-to-server call.

thanks for reply.
When the game ends, Unreal DS needs to notify Nakama that the corresponding match has ended. The judgment of the end of the match is based on the state. Can I consider DS as a presence of the match? When DS starts the game, it establishes a RealtimeClient with Nakama. However, would each DS require a User ID to be allocated, and the User ID needs to be destroyed when the game ends? It seems quite complicated. Can I do this?

I would like the corresponding Nakama match to end and the players inside the match to also exit when DS ends.

I would not recommend adding the Unreal server as a presence in the match.

Can I ask why you need to run an authoritative Nakama match in parallel with the Unreal server match?

The recommended approach here would be to have the Unreal server communicate with Nakama via server-to-server RPCs. There would be no need to create a Match in Nakama.

For example, when the game starts, the Unreal server calls an RPC on Nakama letting it know the following:

  • Expected players and their state
  • Game/match settings
  • Anything else relevant to your game

When the game ends, the Unreal server calls an RPC on Nakama letting it know the game ended, perhaps the final game state and who won.

The current process is to use Nakama for player matching, allowing players to join the match, perform game-related operations such as character selection, and finally, the host starts the game. Nakama creates an Unreal DS and instructs players to connect to the DS to start the game. Nakama provides matching and character selection functions, while the Unreal DS handles the actual gameplay during the game.

Understood. So it sounds like there is some initial data exchange that is done between players once they have been matched together via Nakama Matchmaking but before the actual game starts (unreal dedicated server). That is fine and makes sense.

I would continue as you are now, using matchmaking to match the players, put them into a match and do the initial data exchange for things like character selection etc and then start the Unreal dedicated server portion of the game.

I would then, at the point at which the dedicated server has begun, have each player notify the match that they have joined the server. Once all players have joined (or after a set timeout period) close the match as it is no longer needed. All communication with Nakama from here on out can be done via server to server RPCs from Unreal → Nakama.

An alternative is you could match players into a Party rather than a Match. This may make more sense unless you have some specific authoritative restrictions in place (such as the host deciding which characters are allowed etc).

I hope this makes sense and helps.

thanks for advice。
Once all players have joined (or after a set timeout period) close the match as it is no longer needed。
The issue is that if a player disconnects and reconnects during the game on the DS, the DS information in the Match state will be lost.
I would like to know if it is possible to implement the following solution: when the DS ends the game, it sends an RPC command to Nakama to set map[matchid]bool as False. The Match loop checks if the map value is false and then closes the Match.

The client should cache the connection details for the dedicated server so that they can reconnect should the connection drop. I would also suggest creating an entry in the Storage Engine that stores the connection information so that players who disconnect / crash mid-match can send an RPC to Nakama to retrieve the connection details again if they have lost it.

I would avoid coupling the dedicated server and Nakama match because you could run into a scenario where the dedicated server instance fails/crashes and the Nakama match never gets notified.

Ultimately what works for you depends entirely on your game and your setup.

1 Like