room are being made but "OnRoomListUpdate" is not being called

Options

Still learning to use PUN 2 use to work one PUN 1 before but i had rebuild my project so i figure i would try to use 2 this time.

I have successfully create a room following online tutorials and i know the room was made cause when i print "PhotonNetwork.CountOfRooms" it shows 1. I'm now trying to make a lobby which show a list of rooms as buttons and codded "public override void OnRoomListUpdate", but when I make a room it never gets call. I even added a print message in there to show up if it i did get called. I keep looking online to find a solotuion but i can't seem to.

This is what i have so for:

using System.Collections;

using System.Collections.Generic;

using Photon.Pun;

using Photon.Realtime;

using UnityEngine;

using UnityEngine.UI;



public class Lobby : MonoBehaviourPunCallbacks

{

   // Start is called before the first frame update


   string gameVer = "1.0";

   public List<Button> buttons;

   public GameObject content;

   public GameObject roomPF;


   void Start()

   {

       PhotonNetwork.GameVersion = gameVer;

       PhotonNetwork.ConnectUsingSettings();

   }


   // Update is called once per frame

   void Update()

   {

       if (PhotonNetwork.IsConnected)

       {


           Debug.Log("coint of rooms: "+PhotonNetwork.CountOfRooms+" count of players: "+PhotonNetwork.CountOfPlayers);

           foreach (var but in buttons)

           {


               but.interactable = true;

           }

       }

       else {

           foreach (var but in buttons)

           {


               but.interactable = false;

           }


       }

   }


   public override void OnConnectedToMaster()

   {

       Debug.Log("connected to Server");

      // PhotonNetwork.NickName = "bob";

       //base.OnConnectedToMaster();


   }




   public override void OnRoomListUpdate(List<RoomInfo> roomList)

   {

       Debug.Log("Room list updated");



         // PhotonNetwork.room

           foreach (Transform child in content.transform)

           {

               GameObject.Destroy(child.gameObject);

           }

           foreach (RoomInfo room in roomList)

           {

              // GameObject room = roomPrefab;


               Instantiate(roomPF, content.transform);

               roomPF.transform.SetParent(content.transform);

               roomPF.GetComponent<RoomButton>().roomName = room.Name;

               roomPF.GetComponent<RoomButton>().playerCount = room.PlayerCount;

               roomPF.GetComponent<RoomButton>().maxPlayer = room.MaxPlayers;

               //roomPF.GetComponent<room>().gameMode = (string)game.CustomProperties["GameMode"];

               //Debug.Log ("game mode"+ game.CustomProperties ["GameMode"]);


           }



   }


   public void MakeRoom()

   {



       // string roomName = PhotonNetwork.LocalPlayer.NickName=" room";

       if (PhotonNetwork.IsConnected)

       {

           Debug.Log("creating room");

           RoomOptions options = new RoomOptions();

           options.IsVisible = true;

           //options.

           options.MaxPlayers = 2;

           PhotonNetwork.JoinOrCreateRoom("test", options, TypedLobby.Default);

           // PhotonNetwork.CreateRoom()


       }

   }


   public override void OnJoinedLobby()

   {

       Debug.Log("join room");

   }


   public override void OnCreatedRoom()

   {

       Debug.Log("created room");

   }


   public override void OnCreateRoomFailed(short returnCode, string message)

   {

       Debug.Log("created room failed");

       base.OnCreateRoomFailed(returnCode, message);

   }


   public override void OnEnable()

   {

       base.OnEnable();

   }


   public override void OnDisable()

   {

       base.OnDisable();

   }

Answers

  • mikebgame
    Options

    I think i might of found the issue i had two MonoBehaviourPunCallbacks scripts running in the same scene.

  • Tobias
    Options

    Actually, if you refactor your project, maybe you want to switch to Fusion. While PUN 2 is in LTS mode and will be around for a while, Fusion is a bigger leap than from PUN Classic to PUN 2.

    Glad you found a solution.