Why created game can become invisible?

Here is a code I use to create room on cloud Photon server and to connect clients to it:


private static Coroutine updateCoroutine; public override void OnConnectedToMaster() { Debug.Log("OnConnectedToMaster"); updateCoroutine = StartCoroutine(this.UpdateGameListCor()); } private IEnumerator UpdateGameListCor() { TypedLobby sqlLobby = new TypedLobby("myLobby", LobbyType.SqlLobby); string sqlLobbyFilter = "C0 = 1"; // request games with mode 0; while (true) { PhotonNetwork.GetCustomRoomList(sqlLobby, sqlLobbyFilter); yield return new WaitForSeconds(1f); } } public override void OnRoomListUpdate(List<RoomInfo> roomList) { Debug.Log("OnRoomListUpdate : " + roomList.Count + " rooms"); // code to show rooms on UI } public void CreateNewGameButtonClick() { Debug.Log("payer connected: " + PhotonNetwork.IsConnected); if (PhotonNetwork.IsConnected) { LoaderModal.Show(); StopCoroutine(updateCoroutine); RoomOptions roomOptions = new RoomOptions(); roomOptions.IsVisible = true; roomOptions.MaxPlayers = 4; // in this example, C0 might be 0 or 1 for the two (fictional) game modes roomOptions.CustomRoomProperties = new ExitGames.Client.Photon.Hashtable() { { "C0", 1 } }; roomOptions.CustomRoomPropertiesForLobby = new string[] { "C0" }; // this makes "C0" available in the lobby // let's create this room in SqlLobby "myLobby" explicitly TypedLobby sqlLobby = new TypedLobby("myLobby", LobbyType.SqlLobby); PhotonNetwork.CreateRoom(GameStorage.PlayerName, roomOptions, sqlLobby); Debug.Log("game created"); } } public override void OnCreatedRoom() { Debug.Log("OnCreatedRoom"); } public override void OnJoinedRoom() { Debug.Log("OnJoinedRoom: " + PhotonNetwork.CurrentRoom.Name); }
This code worked properly for some short time. Rooms were created properly and appeared on UI, clients could connect to them without any errors. But suddenly (no code changes were applied) rooms became invisible. OnRoomListUpdate() method started receiving empty list. Although the room is created properly and has IsVisible property set to true. Player who creates room receives OnJoinedRoom() callback where I can see created room details.

So, what am I doing incorrectly?

Thanks in advance.

Best Answer

  • DIN
    DIN
    Answer ✓
    I found a reason why taht happened for me. It appeared that clients had different Product Name in player settings which made created room invisible for each other.
    Anyway, thanks for your ideas!

Answers

  • Hi @DIN,

    when OnRoomListUpdate is called, you can use PhotonNetwork.GetRoomList to access the internally cached room list, which should contain each available room.

    You can also take a look at the API documentation for GetCustomRoomList to see how to use it correctly.
  • Thank you for you answer but it seems that PUN 2 has no PhotonNetwork.GetRoomList() method. At least it says that PhotonNetwork does not have a definition for GetRomList.
  • For some reason when player creates a room and recieves OnCreatedRoom() and OnJoinedRoom() callbacks, PhotonNetwork.CountOfPlayersInRooms and PhotonNetwork.CountOfRooms are still zero despite PhotonNetwork.InRoom is true and PhotonNetwork.CurrentRoom contains room info.
    Also, it is impossible to connect created room from another client by its name. "Game does not exist" error is returned in OnJoinRoomFailed() callback.
  • Hi @DIN,

    I didn't notice, that this is about PUN 2. In PUN 2 there is no internal caching of the room list, you would have to do this on your own. To see how this works, you can take a look at the Asteroids demo and especially its LobbyMainPanel class. This one contains all the logic related to caching a room list and deal with the OnRoomListUpdate callback.

    In PUN 2, PhotonNetwork.GetRoomList is not available any longer, you have to use the OnRoomListUpdate callback according to the Migration Notes.

    PhotonNetwork.CountOfPlayersInRooms and PhotonNetwork.CountOfRooms are only available, when the client is inside the lobby, not in the room.

    Also, it is impossible to connect created room from another client by its name. "Game does not exist" error is returned in OnJoinRoomFailed() callback.


    Please make sure, that the client, who wants to join the room, is in the same lobby the room has been created in.
  • DIN
    DIN
    Answer ✓
    I found a reason why taht happened for me. It appeared that clients had different Product Name in player settings which made created room invisible for each other.
    Anyway, thanks for your ideas!