Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Unity Multiplayer PUN - load level when room is full

Discussion in 'Multiplayer' started by TomPo, Jun 20, 2015.

  1. TomPo


    Nov 30, 2013
    Confusing, thought that in Update void parameters will be changing automaticly but it would be to easy, right?
    So how to make to load level for all players in the room but only when room is full?
    What I have:
    - player is joining lobby and automaticaly start searching for matched SQL room
    - when find one, properties of this room are change

    Now, when room is full - load scene
    Right now just last joined player to the room is moved to the level, rest of players which are already in this room can't see that the room is full and ready to load scene.
    For now it's just one script included to empty object, no Photon|View no nothing, want to add all of these into the scene with game mode where players will be spawned.

    Piece of code:
    Code (csharp):
    2.    void Start(){
    3.        DontDestroyOnLoad(gameObject);
    4.        PhotonNetwork.automaticallySyncScene = true;
    5.     }
    7.     public void OnJoinedRoom()
    8.     {
    9.         if (PhotonNetwork.connected == true) {
    10.             if ( == max) {
    11.                 PhotonNetwork.LoadLevel(1);
    12.             }
    13.         }
    14.     }
    16.     void Update () {
    17.         if(PhotonNetwork.connected)
    18.         {
    19.             if(in_room){
    20.                 int countPlayers =;
    21.                 if((countPlayers == max){
    22.                     PhotonNetwork.LoadLevel(1);
    23.                 }
    24.             }
    25.         }
    26.     }
    Tried so far:
    - change all players CustormProperties via foreach and change hashtab parameter from 0 to 1
    - RPC but no success

    Why the hell void Update doesn't see updates ? but exacly wknows f.e. if player is in the room or not. Why room properties are not updated?
    Last edited: Jun 20, 2015
  2. tobiass


    Apr 7, 2009
    I guess the problem is related to your code. The script starts to load the level when max players are in the room. It attempts to do this every single frame, once the conditions are met. And in load level, pun will also attempt to set a property for the level name - every frame...
    I have no idea what Unity will do in that case...

    There is a callback for player joined. Use it and check player count in there. If max is reached, let only the master client call load level. The others will follow, because you enabled automatic sync of scene.