Skip to main content

Creating a lobby

Lobbies are like sessions, except that lobby data, lobby member data and the member list is automatically kept in-sync for all of the clients who are in the lobby. Sessions don't automatically synchronise player lists from the host of the match to clients.

Lobbies can't be used by dedicated servers.

Lobbies and parties both use "EOS Lobbies" under the hood, which is why you can join a party from a lobby search result.

Prerequisites

If you're using C++, you'll need to add the Online Interfaces headers to your project so you can access the lobby APIs.

If you're using Online Subsystem Blueprints, you don't need to do any additional steps to access the lobby APIs.

Create a lobby

To create a lobby, first get the online lobby interface:

#include "OnlineSubsystem.h"
#include "OnlineSubsystemUtils.h"
// If your project can't find this header, make sure you have installed the headers from here:
// https://src.redpoint.games/redpointgames/online-interfaces/
#include "OnlineLobbyInterface.h"

// ...

IOnlineSubsystem* Subsystem = Online::GetSubsystem(this->GetWorld());
TSharedPtr<IOnlineLobby, ESPMode::ThreadSafe> Lobby = Online::GetLobbyInterface(Subsystem);

Then, make a lobby transaction for creating the lobby:

TSharedPtr<const FUniqueNetId> LocalUserId = Identity->GetUniquePlayerId(0);
TSharedPtr<FOnlineLobbyTransaction> Txn = Lobby->MakeCreateLobbyTransaction(*LocalUserId.Get());

// To enable voice chat on a lobby, set the special "EOSVoiceChat_Enabled" metadata value.
Txn->SetMetadata.Add(TEXT("EOSVoiceChat_Enabled"), true);

// To allow clients connecting to the listen server to join the lobby based on just the ID, we need
// to set it to public.
Txn->Public = true;

// Here you can adjust the capacity of the lobby.
Txn->Capacity = 4;

// Setting a lobby as locked prevents players from joining it.
Txn->Locked = false;

Then, create the lobby:

if (!Lobby->CreateLobby(
*LocalUserId.Get(),
*Txn,
FOnLobbyCreateOrConnectComplete::CreateLambda([](
const FOnlineError & Error,
const FUniqueNetId & UserId,
const TSharedPtr<class FOnlineLobby> & CreatedLobby)
{
if (Error.WasSuccessful())
{
// The lobby was created successfully and is now in CreatedLobby.
FString IdStr = CreatedLobby->Id->ToString();

// You'll need to store IdStr somewhere, as that is what needs to be sent to connecting clients.
}
else
{
// Lobby could not be created.
}
})))
{
// Call failed to start.
}