Search Unity

Third Party [Photon PUN] How can I organize lobbies?

Discussion in 'Multiplayer' started by Paulx774, Jul 8, 2021.

  1. Paulx774

    Paulx774

    Joined:
    Mar 18, 2021
    Posts:
    103
    As far as I understand, Photon's logic is like this:
    - The client connects to the master server
    - The client joins to a lobby
    - The client can see the rooms in that lobby

    I have 2 different game modes in my game. A client can only see the rooms in the lobby they're in. I would like to organize players depending on the game mode they select. For example; Client 1 wants to play Game Mode A and Client 2 wants to play Game Mode B. In this example; there should be 2 lobbies. Client 1 joins to Lobby X, Client 2 joins to Lobby Y. So, they don't see each others in the room list. How can I do that?
     
  2. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,066
    The "Lobbies" doc page should help here.
    In general, you are right. Make up two lobbies (different names) and whenever a room gets created, pass the relevant lobby, so it gets associated with it.
    We usually don't recommend to join a lobby (and list rooms) as players tend to not really select a room for a good reason but for being in the top 5 results or so. The ping is the same in all cases...
     
    Paulx774 likes this.
  3. Paulx774

    Paulx774

    Joined:
    Mar 18, 2021
    Posts:
    103
    Basically, the code should be like this?

    Code (CSharp):
    1.     TypedLobby freeAllLobby = new TypedLobby("FreeAll", LobbyType.Default);
    2.     TypedLobby teamDMLobby = new TypedLobby("TeamDM", LobbyType.Default);
    3.  
    4.     public void CreateRoom_FreeAll()
    5.     {
    6.         // ... Set the room options
    7.  
    8.         PhotonNetwork.CreateRoom(nickname, roomOptions, freeAllLobby);
    9.     }
    10.  
    11.     public override void OnConnectedToMaster()
    12.     {
    13.         switch (gameMode)
    14.         {
    15.             switch EGameMode.FreeAll:
    16.                 PhotonNetwork.JoinLobby(freeAllLobby);
    17.                 break;
    18.             switch EGameMode.TeamDM:
    19.                 PhotonNetwork.JoinLobby(teamDMLobby);
    20.                 break;
    21.             default:
    22.                 break;
    23.         }
    24.     }
    I also heard that there's a player limit for every lobby. There can't be more than 16 players in a lobby. Is that true? If so, what would happen in the code above if the 17th player wants to connect to the same lobby?
     
    russisunni and LikeSauR like this.
  4. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,066
    Yes, the code may look like that.
    In Photon matchmaking, Lobbies are lists of rooms, used to find a suitable room to join. Players have no impact on those lobbies, so there is no such limit.
    In rooms, there is a player limit, correct. This is due to PUN 2's approach to syncing the networked objects. The more players there are, the more traffic this causes and at some point you'd run into performance problems.
    You have to set the MaxPlayers value in the RoomOptions to <= 16.
    If this cap needs to be lifted, mail us: developer@photonengine.com. It's possible but we'd like to greenlight the usage, knowing a little about the case.
     
    Paulx774 likes this.