Start level with all network players at the same time

Hello,

I searched everywhere and can't find an answer.

What is the best way to start a level with all network players at the same time? All the examples have players popping in whenever. I need to wait for players and then start a race on the level loaded.

Do you do this with the unity time or is there a photon function that syncs that information?

Thanks,
Dennis

Comments

  • PhotonNetwork.time is synchronized. You could send an RPC that the round starts at time + X and announce the start ahead of time.
    You can set Room.open to false, so no players can join anymore, even if not full. And you can hide the room from matchmaking by setting Room.visible to false.
    If you want people to join for the next round, the new players need to know since when the round is running, so you can either buffer the RPC or set a room property with Room.SetCustomProperties. Set something like key "st" (for "starttime") and a time value.
  • Thanks, that is helpful.

    So my current scenario is that I want all players to join the same scene at the same time, but the timing on some clients is 6 seconds apart.

    I use:

    PhotonNetwork.automaticallySyncScene = true;

    Then:

    if (PhotonNetwork.isMasterClient) {
    //only the master client may load the level.
    PhotonNetwork.LoadLevel (loadedSettings.trackToRace);
    }

    When the master loads the level, it triggers everyone to load level, but they are all behind the master client. There is a countdown to race and they are seconds off.

    What am I missing? do I need to use PhotonNetwork.time? And I don't see how that would change things.
  • Hi there,
    Could you get one of the players to wait until the others have entered the room then send an RPC message to kick the start off?
  • > Do I need to use PhotonNetwork.time? And I don't see how that would change things.
    What other options do you have? Each client's time comes from some clock which might be correct or not. Most are not perfect.

    Petey: I don't know who you ask but: Yes. See above: Set a start time and let everyone trigger the start then.
  • Well, I do start the level at the same time. the level load is sent to all clients, but they are behind the server by seconds because it takes the clients different times to load the level on the different hardware.

    So trying to figure out how to start the game at the same time over the network. since this isn't working well enough.
  • In that case, you don't need a timer but you need "OK" messages by the clients you're waiting for.
    When the level is loaded, send an RPC "LevelLoaded". Each client should have a list to track if all are OK and the Master Client can then start the level when that's the case.
  • Hi Tobias,

    just wanted to let you know something is wrong with PhotonNetwork.LoadLevel + automaticallySyncScene = true in the last couple versions of Unity (tested on 5.6.1 and 2017.1). I can see that the MC GO instantiates on the other clients BEFORE the scene has loaded (and I'm instantiating on the scene loaded handler, of course), and then it gets destroyed because the original scene unloads causing a lot of mess when the right scene finally loads.

    The code is almost identical to what I used about a year ago, so I don't think I've messed something up, but something is changed either in the way Unity loads scenes or how you handle stopping network communication... or both. :smile:

    Anyway, I've fixed it by making RPC calls to count the number of ready players, and once it reaches the player count in the room, I start instantiating GOs.

    I'm really curious about what happened. Spent a few hours researching.
    Cheers