I'm trying to make a multiplayer game where there are multiple levels. All these levels will have different rooms, each with a max player count of 4.


  1. player selects a level
  2. check if there is an existing room for that level that hasn't met the max player count
  3. if there is such room, join the room; if not, create a new room for the level
  4. wait until the room's player count reaches 4
  5. start game

I know that Photon has something called JoinOrCreateRoom with max player options, but with this, wouldn't there be no way to create rooms with different names?

My idea is that the room names would be: levelNumber + "_" + orderOfTheRoomInLevel For example, the 3rd room of level 1 would be named 1_3. This way, I could keep track of how many rooms there are per level by increasing the number whenever the player creates a room.

My code is:

public void StartRoomMatch(int level)
    roomList = PhotonNetwork.GetRoomList().ToList();
    RoomOptions options = new RoomOptions();
    options.MaxPlayers = 4;
    options.EmptyRoomTtl = 1;

    if(CheckIfRoomExists(level + "_" + roomNumsPerLevel[level]))
        if(player count of room by name < 4)
            PhotonNetwork.JoinRoom(level + "_" + roomNumsPerLevel[level]);
            PhotonNetwork.CreateRoom((level + "_" + (++roomNumsPerLevel[level]), options, TypedLobby.Default);
    else //this is the first room being created in the level
        PhotonNetwork.CreateRoom((level + "_" + roomNumsPerLevel[level], options, TypedLobby.Default);
    // PhotonNetwork.JoinOrCreateRoom(level + "", options, TypedLobby.Default);

private bool CheckIfRoomExists(string roomName)
    RoomInfo room  = roomList.FirstOrDefault(r => r.Name == roomName);
    return (room != null);

The problem is, I don't know what to fill in in the second if statement.

Is this an effective way of level matchmaking? If not, what would be a good way? (It is my first time using Photon Server so I would appreciate a detailed explanation) If yes, how do I get the player count of a room by the room's name?

  • \$\begingroup\$ Not to sure about Photon, but if you start the game, what happens with the room? Should it not be removed? If it is you do not need to have the orderOfTheRoomInLevel part and only check against the level \$\endgroup\$
    – Zibelas
    Commented Feb 10, 2022 at 11:50
  • \$\begingroup\$ @Zibelas Thank you for the insight! I'm not too sure about Photon either, but I think maybe closing the room after the max player count has been met might work \$\endgroup\$ Commented Feb 11, 2022 at 2:19

1 Answer 1


You cannot change the name of a room once you've created it. While you can still use the room/level naming convention for the name of the room, you will have to create another script to display the player count in each room. You could use the PhotonNetwork.CurrentRoom.PlayerCount function in that separate script, I think that would help you more.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .