Facing Problems in getting roomlist in unity photon networking
Options
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.
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; } }
0
Comments
-
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 usingPhotonNetwork.JoinLobby()
Make sure you are joined to a lobby usingOnJoinedLobby()
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 usingforeach
(GC overhead) or getting the list inUpdate()
.
Instead get the list inside theOnReceivedRoomListUpdate(
) callback.0 -
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...0 -
@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...0 -
@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;
}
}0 -
What is the required behaviour and what are you getting?0