I'm encountering an issue with room list synchronization in Unity using Photon Unity Networking 2 (PUN2). Here's a detailed explanation of the problem:
I have implemented a room listing feature where available rooms are displayed in a scroll view. The issue arises when creating rooms from different instances of the game.
Steps to Reproduce:
- Start instance 1 and create a room.
- Start instance 2 and create another room.
- Observe the room list in instance 3. Expected Behavior: I expect both rooms created in instances 1 and 2 to be listed in the room view of instance 3.
Actual Behavior: However, what happens is that the room created in instance 2 replaces the room created in instance 1 in the room list of instance 3.
Code Snippets: Here's the relevant part of the code where I handle the OnRoomListUpdate callback:
public override void OnRoomListUpdate(List<RoomInfo> _roomList)
{
ClearRoomList();
roomList = _roomList;
foreach (RoomInfo room in roomList)
{
GameObject roomItemObj = Instantiate(roomItemPrefab,content);
roomItemObj.transform.Find("Name of Room").GetComponent<TextMeshProUGUI>().text = room.Name;
roomItemObj.transform.Find("players in room").GetComponent<TextMeshProUGUI>().text = room.PlayerCount+"/"+room.MaxPlayers;
roomItemObj.GetComponent<Button>().onClick.AddListener(delegate {PhotonNetwork.JoinRoom(room.Name);});
}
LogCurrentRoomList();
}
Any help or insights into why the room list is not being consistently maintained across instances would be greatly appreciated.
Thank you!