Sync Random Maze Generator/Random Seed for all Players in Room
So I have an object that is created by a Manager object script with InstantiateRoomObject at Start().
PhotonNetwork.InstantiateRoomObject(world, Vector3.zero, Quaternion.identity);
The World object contains a mazeSpawner script that generates a maze in Start(), based on a random seed.
RandomSeed = Random.Range(11111, 99999);
Random.seed = RandomSeed;
In order to sync the maze for all players, at first I put a PhotonView on every maze object but that led to 999+ photonView IDs, so instead I figured I could probably just sync the maze seed across all players.
I gave up trying to use the customProperties, and instead am going with RPCs, but I have been unable to get it working and I have been trying for more than a day now. I tried calling this at the beginning of the Start(),
photonView.RPC("SetSeed", RpcTarget.All);
[PunRPC]
public void SetSeed()
{
RandomSeed = Random.Range(11111, 99999);
Random.seed = RandomSeed;
}
But this results in all players still having random, separate seeds AND only on the master's side, does the maze fully generate. For the other clients, only about half the maze is generated, as if it were interupted. Next I tried calling the RPC using IsMasterClient which led to only the Master client to getting a randomized fully generated maze while for the clients, they had seeds which exceeded the set range and even went into the negatives and the maze was again only about half.
Afterward, i tried various combinations of switching the Random.Range and Random.Seed lines from the RPC to the Start(), and calling those lines and the RPC in the Start() or IsMasterClient. But I just got similar, incorrect results.
So how I can sync a random.range value across a server for all players, so that that value can be used for a random maze generator seed?
Answer by VanToRiaXVII · 4 days ago
I'm not exactly sure how variable synchronization in Photon PUN works, but from what I could see, you'd need to send the seed number to the client, not the function that generates the seed. Otherwise, it'll obviously keep getting a different number for each client every time it's getting called.
Your answer
Follow this Question
Related Questions
Sync movements Photon 0 Answers
Photon Sync Var 1 Answer
How to sync RPC function Photon Network? 1 Answer
Unitys standard third person controller for multiplayer? 1 Answer
How to sync a property?? 0 Answers