PUN2 OnRoomListUpdate() not called while in room

I am caching the room list in my client using the same code as in the Asteroids demo. The problem I am having is that I do not get an update if the rooms change while already in a room. For example:

Client A creates a new Room (Room 1)
Client B gets the room list. Sees Room 1.
Client B creates a new Room (Room 2).
While Client B is in Room 2, Client A leaves Room 1.
Client B leaves Room 2.

Client B does not get notified that Room 1 no longer exists, and it shows up on the room list. When Client B tries to join Room 1 it fails and Room 1 is not removed from Client Bs cached room list.

Comments

  • Hi @PabloBot,

    it is expected that the client doesn't receive any room list updates while he is in a room. You can try to clear the locally stored room list when entering a room or after having joined a room. Later, when leaving the room, the client should receive an up-to-date room list as soon as he has entered the lobby (is connected to the MasterServer) again.
  • Thanks for the response @Christian_Simon I am going ahead and clearing the cached room list when OnJoinedRoom() fires. It seems to be working as intended now. FYI, the asteroids demo has the same issue as I described above and is reproducible with those same steps. It may help others if you correct the demo to also clear the room list. I would have seen that and been able to fix it if it had.
  • Hi @PabloBot,

    thanks for your feedback.

    The Asteroids demo already contains calls for clearing the cached rooms list, however the OnLeftLobby callback, containing those calls, gets not called when the client joins the room. To make sure, the cached rooms list gets cleared correctly, you have two options. You can either use the OnJoinedRoom callback and clear the cached rooms list from there or you can manually leave the lobby by using PhotonNetwork.LeaveLobby();. This has to be added two times to the demo's source code. The first occurrence is at the beginning of the OnBackButtonClicked function. Here you can add the following code snippet:
    if (PhotonNetwork.InLobby)
    {
        PhotonNetwork.LeaveLobby();
    }
    The second occurrence is in the RoomListEntry class where the onClick handler for the button is set up. After modification the source looks like this:
    public void Start()
    {
        JoinRoomButton.onClick.AddListener(() =>
        {
            if (PhotonNetwork.InLobby)
            {
                PhotonNetwork.LeaveLobby();
            }
    
            PhotonNetwork.JoinRoom(roomName);
        });
    }
    For the demo we have used the second option, so this fix will be part of the next update of the PUN 2 package.
Sign In or Register to comment.