- Home /
Network - Sync a seed random number at the start of the game
Hello, I have a simple network game - two cars (one server the other is client) and a random generated environment. for the latter to be equal in both of the instances of the game I need to generate random seed at the server and then pass it to the clients at the start of the game. How can I do that?
I tried:
[SyncVar] int randomSeed;
void Start() { CmdGenerateNumber(); }
[Command] void CmdGenerateNumber() { randomNumber = Random... RpcDoOnClients(); }
[ClientRpc] { Generate level by the seed... }
I guess the problem with that solution is that I don't send to another client in time... the server make the calculation and then send only to itself (as a client) How can I verify the existence of the two cars and only then activate the sequence of generating in server and then send to clients? Thanks :-)
Answer by yanivng · Oct 03, 2017 at 07:26 AM
You can generate a GUID (System.Guid.NewGuid()), send it to both the clients and use it as a seed to the random generator you are using. Game will start running in the client only after the start message (carrying the seed) has arrived. Let me know if that helps, or if you need more information.
Hi Yaniv, Where the guid should generated? inside the server? I didn't understand that line - "Game will start running in the client only after the start message (carrying the seed) has arrived". thanks!
And thanks but my problem is not the random seed... the problem is where to generate it and when to publish it to all clients.
Can you please elaborate: how does the server communicate with the clients? Do the game start in a client without contacting the server first?
Hi, I'm using the standard networking library. the game starts (go to the playing scene) after 2 players joining - one as the host & server and the other as the client
In this case, the client must wait for a message from the server containing the seed, and only then start the actual logic which is randomly generated
Your answer
![](https://koobas.hobune.stream/wayback/20220612140149im_/https://answers.unity.com/themes/thub/images/avi.jpg)