Facing Problems in getting roomlist in unity photon networking

Options
Hasi
Hasi
Hello Guys!

I am facing problem of getting rooms list. I have tried everything I read all the other questions related to topic but none of them helped me out. How can I get rooms created in game. Here is the that I have written. Any help would be appreciated.

public GameObject RoomBoardEntry;
 public GameObject RoomBoardPanelParent;

 // Update is called once per frame
 void Update () {
         foreach (RoomInfo room in PhotonNetwork.GetRoomList()) {
             Debug.Log (room.Name+ " Name ");
             GameObject RoomObject = (GameObject)Instantiate (RoomBoardEntry);
             RoomObject.transform.SetParent (RoomBoardPanelParent.transform);
             RoomObject.transform.Find ("NameHeader").GetComponent<Text> ().text = room.name;
         }
     }

Comments

  • JohnTube
    JohnTube ✭✭✭✭✭
    edited July 2017
    Options
    Hi @Hasi,

    Thank you for choosing Photon!

    You need to be joined to a lobby (of default type) to receive the list of rooms created in that same lobby.
    By default, if you enable "Auto Join Lobby" from PhotonServerSettings you will auto join the default lobby (default type, name is null).
    If you use another lobby, join it explicitly using PhotonNetwork.JoinLobby()
    Make sure you are joined to a lobby using OnJoinedLobby() callback.
    FYI: When you are joined to a room you can't get the list though as you are on another server.
    And I do not recommend using foreach (GC overhead) or getting the list in Update().
    Instead get the list inside the OnReceivedRoomListUpdate() callback.
  • Hasi
    Options
    Hi @JhonTube,
    Thanks for your reply and I am sorry to reply in this thread late.

    The info you gave me was quite informative and I Have enable Auto join lobby option in photonserversetting but the problem is that I am not getting how to use OnRecievedRoomListUpdate(). I read docs about this but to be honest I am getting how to use it. Can you kindly give me some code sample that how can i use it. i will be thankful to you...
  • Hasi
    Options
    @JohnTube

    Thanks for your reply and I am sorry to reply in this thread late.

    The info you gave me was quite informative and I Have enable Auto join lobby option in photonserversetting but the problem is that I am not getting how to use OnRecievedRoomListUpdate(). I read docs about this but to be honest I am getting how to use it. Can you kindly give me some code sample that how can i use it. i will be thankful to you...
  • Hasi
    Options
    @JohnTube

    This what i have done but i am not getting required behavior...

    void OnReceivedRoomList(){
    Debug.Log ("Daze");
    foreach (RoomInfo room in PhotonNetwork.GetRoomList()) {
    Debug.Log (room.Name+ " Name ");
    GameObject RoomObject = (GameObject)Instantiate (RoomBoardEntry);
    RoomObject.transform.SetParent (RoomBoardPanelParent.transform);
    RoomObject.transform.Find ("NameHeader").GetComponent ().text = room.name;
    }

    }
  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    What is the required behaviour and what are you getting?