Joining a lobby
You can join a lobby in one of two ways:
- You've previously searched for lobbies and found a result you want to join, or
- You've received a lobby ID from somewhere and parsed it
Joining a lobby
- C++
- Blueprints
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
- C++
- Blueprints
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
Internally parties are built on top of lobbies. Therefore, if you join a lobby that was originally created as a party, joining the lobby will cause the player to also join the party.
Tip
In previous versions of the plugin you needed to explicitly "join lobby as party". This is no longer necessary in the current version of the plugin. Whether you join the lobby as a party is determined solely based on whether the lobby was created as a party by the host.