Search Unity

Third Party Photon PUN - How to handle OnRoomListUpdate function?

Discussion in 'Multiplayer' started by Paulx774, Jul 22, 2021.

  1. Paulx774

    Paulx774

    Joined:
    Mar 18, 2021
    Posts:
    103
    I'm trying to list of rooms in my game, however, I couldn't understand how OnRoomListUpdate works. This is my code to list the rooms:
    Code (CSharp):
    1.     List<RoomInfo> Rooms = new List<RoomInfo>();
    2.  
    3.     public override void OnRoomListUpdate(List<RoomInfo> roomList)
    4.     {
    5.         Rooms.Clear();
    6.         foreach (var item in roomList)
    7.         {
    8.             if (!item.IsVisible || !item.IsOpen || item.RemovedFromList)
    9.                 continue;
    10.  
    11.             Rooms.Add(item);
    12.         }
    13.  
    14.         // ... clear the all rooms from the UI
    15.         // ... fill the UI with the new 'Rooms' variable
    16.     }
    The function sometimes return a list with zero element even though there's an active room. What that function returns to me exactly and how can I list the room list.
     
  2. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,066
    You should not clear the list you got. The update is adding/removing rooms or updating their values. If you wipe the list and not much changes, you show far less rooms than available.

    It may take a moment to update the room list on the Master Server (after a room got created) and the updates are sent in 5 or 10 second intervals (so the update to the client is not immediate either).

    The update itself should not be empty entirely, unless you just joined the lobby (when you join, you get the initial list, which can be empty ofc).
     
    LuckyMisterSleven and Paulx774 like this.
  3. Paulx774

    Paulx774

    Joined:
    Mar 18, 2021
    Posts:
    103
    So, that function only returns the rooms that are changed, but initially it returns the entire rooms in the lobby. Thank you.
     
  4. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,066
    Yes, exactly.
    You could consider the first call an update, too, as the client knows of zero rooms.