PhotonNetwork.GetRoomList() always returns empty

    void Awake()
    {
        PhotonNetwork.autoJoinLobby = true;
        PhotonNetwork.automaticallySyncScene = true;
        PhotonNetwork.lobby = TypedLobby.Default;
        PhotonNetwork.logLevel = Loglevel;
        PhotonNetwork.ConnectUsingSettings(gameVersion);
    }

    [ContextMenu("Show Room List")]
    public void showRoomList() {
        Debug.Log(PhotonNetwork.inRoom + " " + PhotonNetwork.insideLobby + " Room List: " + JsonUtility.ToJson(PhotonNetwork.GetRoomList()));
        //foreach (RoomInfo room in PhotonNetwork.GetRoomList()) {
        //    Debug.Log("Room: " + room.Name);
        //}
    }

    [ContextMenu("Join room")]
    public void joinRoom() {
        RoomOptions roomOptions = new RoomOptions();
        roomOptions.IsVisible = true;
        PhotonNetwork.JoinOrCreateRoom("test1", roomOptions, PhotonNetwork.lobby);
    }
To reproduce

I start up my test on 2 machines

run showRoomList on 1, see: false true Roomlist: {}
run joinRoom on 1, re run showRoomList on 1, see: true flase Roomlist: {}

run showRoomList on 2, see: false true Roomlist: {}
run joinRoom on 2, re run showRoomList on 2, see: true flase Roomlist: {}

re run showRoomList on 1, see: true flase Roomlist: {}

at this point both players are in the same room and can interact with each other, but at no point during the process did the room ever show up in the list.

Comments

  • Hi @wirelessdreamer,

    please note, that the room list is only available when the client is inside a lobby and not in a room. When creating the room with JoinOrCreateRoom or CreateRoom you can also use 'null' as third parameter since you are using the default lobby. If you however create the room with a specific lobby, the client who calls GetRoomList() have to be inside the same lobby in order to get the room list.
  • Hi @wirelessdreamer,

    please note, that the room list is only available when the client is inside a lobby and not in a room. When creating the room with JoinOrCreateRoom or CreateRoom you can also use 'null' as third parameter since you are using the default lobby. If you however create the room with a specific lobby, the client who calls GetRoomList() have to be inside the same lobby in order to get the room list.

    So with this approach

    I start up my test on 2 machines

    run showRoomList on 1, see: false true Roomlist: {}
    run joinRoom on 1, re run showRoomList on 1, see: true flase Roomlist: {}

    run showRoomList on 2, see: false true Roomlist: {} - shouldn't this command return a room?
  • shouldn't this command return a room?


    If the room has been created in the same lobby the client currently is in and if the room is visible (default), it should be listed in the room list. I honestly don't know what JsonUtility.ToJson(PhotonNetwork.GetRoomList()) should return. Have you already tried logging something different, for example PhotonNetwork.GetRoomList().Length in order to see if the room is counted here?
  • JohnTube
    JohnTube ✭✭✭✭✭
    edited December 2017
    Hi @wirelessdreamer

    Thank you for choosing Photon!

    I wanted to add to the comments of my colleague @Christian_Simon the following:

    It could be a timing issue, PhotonNetwork.GetRoomList() returns a cached list of rooms that are set and updated after each OnReceivedRoomListUpdate callback. So I suggest the following:
    void OnReceivedRoomListUpdate() 
    {
        var roomsList = PhotonNetwork.GetRoomList();
        for(int i=0; i<roomsList.Length; i++){
            Debug.LogFormat(this, "[{0}] - {1}", i, roomsList[i].Name);
        }
    } 
  • JohnTube said:

    Hi @wirelessdreamer

    Thank you for choosing Photon!

    I wanted to add to the comments of my colleague @Christian_Simon the following:

    It could be a timing issue, PhotonNetwork.GetRoomList() returns a cached list of rooms that are set and updated after each OnReceivedRoomListUpdate callback. So I suggest the following:

    void OnReceivedRoomListUpdate() 
    {
        var roomsList = PhotonNetwork.GetRoomList();
    } 
    This was the solution to my issue. Thanks