I’m developing a multiplayer game which uses physics with Unity.
I want to use an authoritative server that simulates physics. For that, I’m using Unity head-less mode which basically runs the game without graphics.
My question is how can I integrate Nakama with that?
Basically I want to use Nakama’s matchmaker to match users but I want my own Unity server to handle the match and its events. How should I implement it?
@mnarimani That’s been done quite a few times with Nakama so far but the exact integration depends on the environment you run servers within but I can give some general advice on the best approach to use:
- Use Nakama for the authentication and other parts of your game server logic.
- Use the
matchmaker_matched
server side hook (intercept function) that is called when players have just been matched. Use that to share the info needed for the players to receive the server details to join the headless Unity instance (once it’s been spun up). - Use the session tokens from each peer to validate on the Unity headless instance that the players joining are who was expected/invited to join.
- Run the authoritative Unity headless game as normal.
Two questions:
1- I run the server on linux (ubuntu). How can I start a program (Unity server) in a lua module?
2- Each match has results. How can I send the result of the match from Unity server to Nakama?
@mnarimani I had assumed you had a more sophisticated setup for the management of your Unity headless instances? What solution did you have in mind to manage that fleet of servers?
1- I run the server on linux (ubuntu). How can I start a program (Unity server) in a lua module?
How best to handle this depends on how you plan to manage the fleet of servers that run the game simulation on the server-side?
2- Each match has results. How can I send the result of the match from Unity server to Nakama?
You can use a server to server (S2S) RPC function call from the Unity headless instance to call back into the Nakama server(s) and update player stats from the results of the match.
https://heroiclabs.com/docs/runtime-code-basics/#server-to-server
Currently the scalability is not important for me. I just need a solution that takes the least amount of time to implement.
What I had in mind was to simply open a new unity instance for each match and close it when match is done.
If scalability is not high priority then it sounds like your suggestion will fit what you need.