For some reason I can no longer see created rooms. Everything was working before but now even my backups which worked fine don't show created rooms. I set the Dev Region to usw. I have both the Player Settings and PhotonServerSettings App Version set to 0.1. Using Name Server, UDP.. I have no Errors. SupportLogger tells me OnRoomListUpdate is being called and showing 0 rooms even when I have a created room running on my Oculus Quest. Here is my lobby script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Photon.Pun;
using Photon.Realtime;
using UnityEngine.SceneManagement;
using System.IO;
using MEC;
using Hashtable = ExitGames.Client.Photon.Hashtable;
/// <summary>
/// to know where the player is in each connecting stage
/// </summary>
public enum connectionState
{
notconnected,
inLobby,
inRoom
}
/// <summary>
/// to know the game Mode
/// </summary>
public enum gameMode
{
Cooperative,
Teams,
battleRoyale
}
/// <summary>
/// This is the most important script that allows the room/lobby connections
/// </summary>
public class PhotonLobby : MonoBehaviourPunCallbacks, IInRoomCallbacks
{
//singleton
public static PhotonLobby lobby;
// connecting/disconnecting icons
public GameObject connectedIcon;
public GameObject disconnectedIcon;
public Text roomLabel;
public Slider maxPlayers;
public Slider roundMinutes;
public RoomDisplay roomDisplay;
private int gameSceneIndex => roomDisplay.gameMapIndex;
//list of rooms used to join an specific room or create one
List<RoomInfo> roomsInfo;
public int Time_minutes => (int) roundMinutes.value > 0 ? (int) roundMinutes.value : 9999;
//the number of created rooms
[Header("The type of game selected", order = 0)]
public gameMode gameMode;
//the number of created rooms
[Header("Number of rooms in the game", order = 0)]
public int numberOfRooms;
//to know whether the player is in lobby
public string roomName;
//to set the number of maximum players of a room
//
int MaxPlayersRoom => (int) maxPlayers.value;
//used to know the connection state
[Header("Shows the connection state of the player", order = 0)]
public connectionState conState;
//photon view attached to this gameobject
private PhotonView PV;
// player variables
Player[] photonPlayers;
[Header("Shows the players in room", order = 0)]
public int playersInRoom;
[Header("The player prefab used to get the initial life", order = 0)]
public GameObject playerPrefab;
//buld index of current scene
int currentScene;
#region UNITY Functions
private void Awake()
{
conState = connectionState.notconnected;
//initialization
PV = GetComponent<PhotonView>();
}
public void Reconnect()
{
PhotonNetwork.Reconnect();
}
public void Disconnect()
{
PhotonNetwork.Disconnect();
}
public void FixedUpdate()
{
//find the connection buttons
connectedIcon = GameObject.FindGameObjectWithTag("connectedIcon");
disconnectedIcon = GameObject.FindGameObjectWithTag("disconnectedIcon");
// set the true or false in function of connection
if (PhotonNetwork.IsConnected)
{
if (connectedIcon != null && disconnectedIcon != null)
{
connectedIcon.SetActive(true);
disconnectedIcon.SetActive(false);
}
}
else
{
if (connectedIcon != null && disconnectedIcon != null)
{
connectedIcon.SetActive(false);
disconnectedIcon.SetActive(true);
}
}
}
public override void OnEnable()
{
base.OnEnable();
//set up singleton
if (PhotonLobby.lobby == null)
{
PhotonLobby.lobby = this;
}
else
{
if (PhotonLobby.lobby != this)
{
Destroy(PhotonLobby.lobby.gameObject);
PhotonLobby.lobby = this;
}
}
DontDestroyOnLoad(this.gameObject);
//// [!] [!] TO MAKE THIS LINE WORK
//CHANGE THE PhotonserverSettings
if (PhotonNetwork.IsConnected == false)
{
PhotonNetwork.ConnectUsingSettings(); //connects to the master photon server
}
//needed to perfom well
PhotonNetwork.AddCallbackTarget(this);
SceneManager.sceneLoaded += OnSceneFinishedLoading;
}
public override void OnDisable()
{
base.OnDisable();
//needed to perform well
PhotonNetwork.RemoveCallbackTarget(this);
SceneManager.sceneLoaded -= OnSceneFinishedLoading;
}
#endregion
#region FAIL EVENTS
// callbacks for errors in logging
public override void OnCreateRoomFailed(short returnCode, string message)
{
DebugOnCanvas.DC.Debug("Tried to create a new room but failed: room with same name exists");
StartCoroutine(restartConnexion());
}
// callbacks for errors in loging
public override void OnJoinRoomFailed(short returnCode, string message)
{
StartCoroutine(restartConnexion());
DebugOnCanvas.DC.Debug("Tried to join a room but failed: " + message);
}
#endregion
#region ON EVENTS
//get the information of the room
public override void OnRoomListUpdate(List<RoomInfo> roomList)
{
base.OnRoomListUpdate(roomList);
roomsInfo = roomList;
RoomDisplay.RD.updateRooms(roomsInfo);
}
// Reset user properties when connected to lobby
public override void OnJoinedLobby()
{
//get name of player
PhotonNetwork.NickName = PlayerInfo.PI.NickName;
//set connection state
conState = connectionState.inLobby;
base.OnJoinedLobby();
DebugOnCanvas.DC.Debug("Joined Lobby");
//set custom properties from player Info and reset the score, kills, etc
Player PY = PhotonNetwork.LocalPlayer;
SetCustomPlayerProp(PY, 0,
0,
0,
playerPrefab.GetComponentInChildren<PlayerHealth>().initialHealth,
PlayerInfo.PI.myHeight,
PlayerInfo.PI.mySkin,
PlayerInfo.PI.myTeam,
PlayerInfo.PI.myGameMode,
PlayerInfo.PI.myMesh);
}
//CALBACK USED to determine if the player is connected to the server
public override void OnConnectedToMaster()
{
DebugOnCanvas.DC.Debug("Player has connected to the photon server");
PhotonNetwork.AutomaticallySyncScene = false;
PhotonNetwork.JoinLobby();
}
// always join lobby to get user/player data
public override void OnLeftRoom()
{
base.OnLeftRoom();
PhotonNetwork.JoinLobby();
}
public void Refresh()
{
GameObject[] gos = GameObject.FindGameObjectsWithTag("roomInstance");
for (int ii = 0; ii < gos.Length; ii++)
{
Destroy(gos[ii]);
}
StartCoroutine(restartConnexion());
}
//this function allows the user to re-connect
IEnumerator restartConnexion()
{
DebugOnCanvas.DC.Debug("Refreshing");
if (PhotonNetwork.IsConnected)
{
PhotonNetwork.Disconnect();
}
while (PhotonNetwork.IsConnected == false)
{
yield return null;
}
yield return new WaitForSeconds(1);
PhotonNetwork.ConnectUsingSettings();
}
#endregion
#region ROOM EVENTS
public void Create()
{
//RETURN if not in lobby
if (PhotonNetwork.InLobby == false)
{
return;
}
//get the number of rooms
numberOfRooms = roomsInfo.Count;
roomName = roomLabel.text;
//we need to make public the variable "Gmode" in the hastable (matchmaking)
string[] str = new string[2];
str[0] = "Gmode";
str[1] = "Map";
// if the room does not exit, create one
RoomOptions roomOps = new RoomOptions()
{
IsVisible = true,
IsOpen = true,
MaxPlayers = (byte) MaxPlayersRoom,
CustomRoomProperties = (new Hashtable(2)
{
{
"Gmode", PlayerInfo.PI.myGameMode
},
{
"Map", roomDisplay.gameMapIndex
}
}),
CustomRoomPropertiesForLobby = str
};
// roomOps.CustomRoomProperties.Add("Map", roomDisplay.gameMapIndex);
//line to create the room
PhotonNetwork.CreateRoom(roomName, roomOps);
DebugOnCanvas.DC.Debug("Created room=" + roomName);
numberOfRooms = roomsInfo.Count;
}
IEnumerator<float> WaitForFade()
{
yield return Timing.WaitForSeconds(5f);
Create();
yield return 0f;
}
// THIS FUNCTION IS USED TO CREATE A ROOM IT WILL BE IN INCREASING ORDER
public void createRoom()
{
Timing.RunCoroutine(WaitForFade());
}
public void createOrJoinRoom(string roomName)
{
//RETURN if not in lobby
if (PhotonNetwork.InLobby == false)
{
return;
}
//we need to make public the variable "Gmode" in the hastable (matchmaking)
string[] str = new string[2];
str[0] = "Gmode";
str[1] = "Map";
// if the room does not exit, create one
RoomOptions roomOps = new RoomOptions()
{
IsVisible = true,
IsOpen = true,
MaxPlayers = (byte) MaxPlayersRoom,
CustomRoomProperties = (new Hashtable(2)
{
{
"Gmode", PlayerInfo.PI.myGameMode
},
{
"Map", roomDisplay.gameMapIndex
}
}),
CustomRoomPropertiesForLobby = str
};
// roomOps.CustomRoomProperties.Add("Map", roomDisplay.gameMapIndex);
//line to create the room
PhotonNetwork.JoinOrCreateRoom(roomName, roomOps, TypedLobby.Default);
}
// when a player joins a room
public override void OnJoinedRoom()
{
base.OnJoinedRoom();
conState = connectionState.inRoom;
DebugOnCanvas.DC.Debug("We are now in a room");
//obtain the players connected
photonPlayers = PhotonNetwork.PlayerList;
//THIS IS THE MAIN CALL
//DebugOnCanvas.DC.Debug("Starting the game");
DebugOnCanvas.DC.Debug("Actual players=" + (PhotonNetwork.PlayerList.Length) + " of possible=" +
(MaxPlayersRoom));
//set custom properties from player Info and reset the score, kills, etc
Player PY = PhotonNetwork.LocalPlayer;
SetCustomPlayerProp(PY, 0,
0,
0,
playerPrefab.GetComponentInChildren<PlayerHealth>().initialHealth,
PlayerInfo.PI.myHeight,
PlayerInfo.PI.mySkin,
PlayerInfo.PI.myTeam,
PlayerInfo.PI.myGameMode,
PlayerInfo.PI.myMesh);
StartGame();
}
//WHEN A NEW PLAYER IS ENTERING THE ROOM
public override void OnPlayerEnteredRoom(Player newPlayer)
{
base.OnPlayerEnteredRoom(newPlayer);
//get the player list information again
DebugOnCanvas.DC.Debug("A new player has joined: " + newPlayer.NickName);
//obtain the players connected
photonPlayers = PhotonNetwork.PlayerList;
playersInRoom = photonPlayers.Length;
}
//decreae the players in room variable when a player leaves the room
public override void OnPlayerLeftRoom(Player otherPlayer)
{
base.OnPlayerLeftRoom(otherPlayer);
DebugOnCanvas.DC.Debug(otherPlayer.NickName + " Has left the game");
//obtain the players connected
photonPlayers = PhotonNetwork.PlayerList;
playersInRoom = photonPlayers.Length;
}
void OnSceneFinishedLoading(Scene scene, LoadSceneMode mode)
{
currentScene = scene.buildIndex;
SceneManager.SetActiveScene(SceneManager.GetSceneByBuildIndex(scene.buildIndex));
//used tow know if the multiplayer scene has been loaded
if (currentScene > 1)
{
//PV.RPC("RPC_CreatePlayer", RpcTarget.All);
CreatePlayer();
}
}
#endregion
#region CREATE PLAYER PREFAB IN NETWORK
private void CreatePlayer()
{
int spawnPicker = Random.Range(0, GameSetUp.GS.spawnPoints.Length);
// [!] this is the directory used to get the most important players' prefab [!] --> playerAvatar
GameObject goInst = PhotonNetwork.Instantiate(Path.Combine("PhotonPrefabs", "PlayerAvatarNew"),
GameSetUp.GS.spawnPoints[spawnPicker].position, Quaternion.Euler(0, 0, 0));
}
#endregion
#region PUBLIC FUNCTIONS CALLED FROM BUTTONS
//called when editing name
public void ChangeName(Text nicknameText)
{
PhotonNetwork.NickName = nicknameText.text;
}
public void StartGame()
{
SceneManagerAsync.SM.goToMultiplayerScene(gameSceneIndex);
}
public void ReturnToLobby()
{
SceneManagerAsync.SM.goToLobby();
}
#endregion
public void SetCustomPlayerProp(Player py, int kills, int deaths, int score, int health, float height, int skin,
int team, string Gmode, int mesh)
{
py.SetCustomProperties((new ExitGames.Client.Photon.Hashtable(1)
{
{"kills", kills},
{"deaths", deaths},
{"score", score},
{"health", health},
{"height", height},
{"skin", skin},
{"team", team},
{"Gmode", Gmode},
{"mesh", mesh}
}));
}
}