Photon v.2 Room Listing

Hello, script that should create room list (I want to show list of room, so Players can See rooms that actually exists and join it) doesn’t work from some reason… I was trying to fix it for some time, but still I can’t get why it’s not working. I guess that OnRoomListUpdata() is not called, but why?

using Photon.Pun;
using Photon.Realtime;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

namespace MyProject
{
    public class RoomListingDisplay : MonoBehaviourPunCallbacks
    {
        [SerializeField]
        private Transform _content; //  ScrollView/ViewPort/Content
        [SerializeField]
        private RoomListing _roomListing;

        private List<RoomListing> _listings = new List<RoomListing>();
        public override void OnJoinedRoom()
        {
            _listings.Clear();
        }

        public override void OnRoomListUpdate(List<RoomInfo> roomList)
        {
            foreach (RoomInfo info in roomList)
            {
                print(info.Name);
                //Removed from rooms list.
                if (info.RemovedFromList)
                {
                    int index = _listings.FindIndex(x => x.RoomInfo.Name == info.Name);
                    if (index != -1)
                    {
                        Destroy(_listings[index].gameObject);
                        _listings.RemoveAt(index);
                    }
                }
                //Added to rooms list.
                else
                {
                    int index = _listings.FindIndex(x => x.RoomInfo.Name == info.Name);
                    if (index == -1)
                    {
                        RoomListing listing = Instantiate(_roomListing, _content);
                        print("Instantiated");
                        if (listing != null)
                        {
                            listing.SetRoomInfo(info);
                            _listings.Add(listing);
                        }
                    }
                    else
                    {

                    }
                }
            }
        }
    }
}

Does your client call PhotonNetwork.JoinLobby()?
And is anyone in the lobby?
When you test, make sure that all clients use the same region (the automatic selection has some outages where different ones are picked).

Aside from that, the code looks fine.

1 Like