Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Third Party Room listing problem. Only list 1 room on reload

Discussion in 'Multiplayer' started by donotprikel, Nov 5, 2023.

  1. donotprikel

    donotprikel

    Joined:
    Nov 14, 2022
    Posts:
    24
    I have a unity game and i have a roomlisting script for photon PUN 2 it works like normal when i create rooms on other computers they all show up BUT when i close the game and reopen it it only shows 1 even though in the editor console it clearly says a controled amount of 6 rooms. Thats not good because when a room is created and a player starts the game right after the room was created the player wont see that open room and cant get into it. How do i fix Please.

    Code (CSharp):
    1. using UnityEngine;
    2. using Photon.Pun;
    3. using Photon.Realtime;
    4. using System.Collections.Generic;
    5. using UnityEngine.UI;
    6. using TMPro;
    7.  
    8. public class RoomListDisplay : MonoBehaviourPunCallbacks
    9. {
    10.     public GameObject roomPrefab;
    11.     public Transform contentPanel;
    12.  
    13.     private void Start()
    14.     {
    15.         // Ensure we are connected to the Photon server and in the lobby
    16.         if (!PhotonNetwork.IsConnected)
    17.         {
    18.             PhotonNetwork.ConnectUsingSettings();
    19.         }
    20.         else
    21.         {
    22.             if (!PhotonNetwork.InLobby)
    23.             {
    24.                 PhotonNetwork.JoinLobby();
    25.             }
    26.         }
    27.     }
    28.  
    29.     public override void OnConnectedToMaster()
    30.     {
    31.         // Join the lobby when connected to the master server
    32.         PhotonNetwork.JoinLobby();
    33.     }
    34.  
    35.     public override void OnRoomListUpdate(List<RoomInfo> roomList)
    36.     {
    37.          Debug.Log("Received room list update. Total rooms: " + roomList.Count);
    38.        
    39.         // Instantiate prefabs for each room (without destroying existing ones)
    40.         foreach (RoomInfo room in roomList)
    41.         {
    42.             GameObject roomEntry = Instantiate(roomPrefab, contentPanel);
    43.             TMP_Text roomNameText = roomEntry.transform.Find("RoomNameText").GetComponent<TMP_Text>();
    44.             TMP_Text maxPlayersText = roomEntry.transform.Find("MaxPlayersText").GetComponent<TMP_Text>();
    45.             Button joinButton = roomEntry.transform.Find("JoinButton").GetComponent<Button>();
    46.  
    47.             roomNameText.text = "Room Name: " + room.Name; // Display the room name
    48.             maxPlayersText.text = "Max Players: " + room.MaxPlayers;
    49.             joinButton.onClick.AddListener(() => JoinRoom(room.Name));
    50.         }
    51.     }
    52.  
    53.     public void JoinRoom(string roomName)
    54.     {
    55.         PhotonNetwork.JoinRoom(roomName);
    56.     }
    57. }
    58.  
     

    Attached Files:

  2. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,022
    I am not sure if you ever remove listed rooms. The updates sometimes include rooms that should no longer be listed.

    Take a look at the Asteroids Demo UI. This implements the room listing properly and if you transfer that to your game, it will work.
     
  3. donotprikel

    donotprikel

    Joined:
    Nov 14, 2022
    Posts:
    24
    Where is the demo ui i cant find it or i just dont know what you mean. Me and my assistant have worked A REDICULOUS AMOUNT OF WORK to try to fiqure this out . i have a few years of experience with unity but still am verry bad at coding and only know verry VERRY little. My assistant has made almost every script but this one is a little to hard we cant fiqure this out.