Create a lobby

When a player creates a new lobby, they can set the following properties with the create call:

  • Lobby name (required

  • Lobby visibility (public or private)

  • Lobby size (the maximum occupancy)

    • This is referred to as Max Players in the code.

  • Initial custom lobby data

    • This can include any arbitrary data. For example, map IDs and game modes.

    • Lobby data with string or numeric values can be indexed, allowing for filtering and ordering on those indexes in queries.

  • Initial (host) player data

    • For example, player display names, skills and characters.

Note: When a player creates a lobby, they automatically become the host.

Create a public lobby

Public lobbies do not require a lobby code to join and are displayed in query results for anyone to join.

The following code sample shows how to create a public lobby:

Copy
C#
string lobbyName = "new lobby";
int maxPlayers = 4;
CreateLobbyOptions options = new CreateLobbyOptions();
options.IsPrivate = false;
                    
Lobby lobby = await LobbyService.Instance.CreateLobbyAsync(lobbyName, maxPlayers, options);

Create a private lobby

Private lobbies are never visible in query results and require the lobby code or ID to be manually provided to new players.

The following code sample shows how to create a private lobby:

Copy
C#
string lobbyName = "new lobby";
int maxPlayers = 4;
CreateLobbyOptions options = new CreateLobbyOptions();
options.IsPrivate = true;
                    
Lobby lobby = await LobbyService.Instance.CreateLobbyAsync(lobbyName, maxPlayers, options);

Create a lobby with standard, non-indexed data

Lobby data can be included in the create request as well as in subsequent update requests.

The following code sample shows how to create a lobby with standard, non-indexed data:

Copy
C#
string lobbyName = "new lobby";
int maxPlayers = 4;
CreateLobbyOptions options = new CreateLobbyOptions();
options.Data = new Dictionary<string, DataObject>()
{
    {
        "ExamplePublicLobbyData", new DataObject(
            visibility: DataObject.VisibilityOptions.Public, // Visible publicly.
            value: "ExamplePublicLobbyData")
    },
};

Lobby lobby = await LobbyService.Instance.CreateLobbyAsync(lobbyName, maxPlayers, options);

Create a lobby with indexed string data

The following code sample shows how to create a lobby with indexed string data:

Copy
C#
string lobbyName = "new lobby";
int maxPlayers = 4;
CreateLobbyOptions options = new CreateLobbyOptions();
options.Data = new Dictionary<string, DataObject>()
{
    {
        "GameMode", new DataObject(
            visibility: DataObject.VisibilityOptions.Public, // Visible publicly.
            value: "Conquest",
            index: DataObject.IndexOptions.S1)
    },
};

Lobby lobby = await LobbyService.Instance.CreateLobbyAsync(lobbyName, maxPlayers, options);

Create a lobby with indexed numeric data

The following code sample shows how to create a lobby with indexed numeric data:

Copy
C#
string lobbyName = "new lobby";
int maxPlayers = 4;
CreateLobbyOptions options = new CreateLobbyOptions();
options.Data = new Dictionary<string, DataObject>()
{
    {
        "MinimumSkillLevel", new DataObject(
            visibility: DataObject.VisibilityOptions.Public, // Visible publicly.
            value: "25",
            index: DataObject.IndexOptions.N1)
    },
};

Lobby lobby = await LobbyService.Instance.CreateLobbyAsync(lobbyName, maxPlayers, options);

Create a lobby with player data for the host

As with lobby data, player data for the host can also be included in the create request instead of adding it with a separate update request.

The following code sample shows how to create a lobby with player data for the host:

Copy
C#
string lobbyName = "new lobby";
int maxPlayers = 4;
CreateLobbyOptions options = new CreateLobbyOptions();
// Ensure you sign-in before calling Authentication Instance.
// See IAuthenticationService interface.
options.Player = new Player(
    id: AuthenticationService.Instance.PlayerId,
    data: new Dictionary<string, PlayerDataObject>()
    {
        {
            "ExampleMemberPlayerData", new PlayerDataObject(
                visibility: PlayerDataObject.VisibilityOptions.Member, // Visible only to members of the lobby.
                value: "ExampleMemberPlayerData")
        }
    });
    
Lobby lobby = await LobbyService.Instance.CreateLobbyAsync(lobbyName, maxPlayers, options);

Active and inactive lobbies

Lobbies are marked as inactive if they haven’t been updated or sent a heartbeat request in the past 30 seconds. You can configure this timeout period. Inactive public lobbies do not appear in query results, and both public and private inactive lobbies are automatically deleted. Inactive lobbies can be reactivated by being updated or sending a heartbeat request.

Because there is a rate limit of 5 heartbeat requests per 30 seconds, users are capped at hosting 5 lobbies at a time. See Heartbeat a lobby for more information.