Skip to main content

Joining a lobby

You can join a lobby in one of two ways:

Joining 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, join the lobby:

if (!Lobby->ConnectLobby(
*LocalUserId,
*LobbyIdFromSearch,
FOnLobbyCreateOrConnectComplete::CreateLambda([](
const FOnlineError & Error,
const FUniqueNetId & UserId,
const TSharedPtr<class FOnlineLobby> & CreatedLobby)
{
if (Error.WasSuccessful())
{
// The lobby was joined successfully.
}
else
{
// Lobby could not be joined.
}
})))
{
// Call failed to start.
}
// ...

Disconnecting from a lobby

To disconnect from a lobby, you'll need the ID of the lobby you previously connected to and call DisconnectLobby like so:

if (!Lobby->DisconnectLobby(
*LocalUserId,
*LobbyIdFromPreviousConnectOrCreate,
FOnLobbyOperationComplete::CreateLambda([](
const FOnlineError& Error,
const FUniqueNetId& UserId)
{
if (Error.WasSuccessful())
{
// Player has been disconnected from lobby.
}
else
{
// Could not disconnect from lobby.
}
})
))
{
// Call failed to start.
}

Joining a lobby as party

First, get the online lobby and party interfaces:

#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"
#include "Interfaces/OnlinePartyInterface.h"

// ...

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

Then, convert your LobbyId to an IOnlinePartyJoinInfoConstPtr:

FString JoinInfo = PartySystem->MakeJoinInfoJson(
*InLocalUserId.GetUniqueNetId(),
InLobbyId);
if (!JoinInfo.IsEmpty())
{
IOnlinePartyJoinInfoConstPtr JoinInfoPtr = PartySystem->MakeJoinInfoFromJson(JoinInfo);
if (JoinInfoPtr.IsValid())
{
// JoinInfoPtr contains the OnlinePartyJoinInfo to pass into JoinParty().
}
}

Once you have the resulting join info, you can proceed to Joining a party.