Parties
Note: Parties uses the Unity Lobby service to group players together. As a result, the Lobby service is a requirement of Parties.
Parties shows how to create a party experience in your game. A party is a group of players, formed by players, that persists for a game session (from game launch to game exit). A party persists across multiple game # states, such as lobby, matchmaking, and gameplay. Unlike a friends list (which is a permanent grouping of players), a party only lasts for the duration of a single game session.
Before continuing, download and install the Unity Hub and a supported version of the Unity Editor. Parties supports the following Unity Editor versions:
- Unity 2020.3 LTS or later
Requirements
Before getting started with Parties, you must meet the following requirements:
- Install the Unity Lobby SDK.
- Your Unity project is onboarded to the Lobby Service.
- TextMesh Pro essentials.
- In the Editor, go to Window > Textmesh Pro > Import TMP Essential Resources.
High-level workflow
A typical party member’s journey using Parties is as follows:
- Player A starts a Party
- Player A sends an invite code to Player B
- Player B Joins Party using the code
- Player A and B are both in a Party, and they start Match 1
- Match 1 ends, and the Party still exists so that Players A and B can play together again in Match 2
Concepts
Parties
A party is a group of players, formed by players, that persists for a game session (from game launch to game exit).
Party leader
A party leader is the host of a party. They manage the party and can add and kick out players.
Party member
A party member is the player who is part of the party. Party members can add other players by sending an invite code.
Manage parties
Use the following Lobby code samples from the LobbyManager to carry out Party operations:
Create a party
async void CreateLobby()
{
try
{
var partyLobbyOptions = new CreateLobbyOptions()
{
IsPrivate = true,
Player = m_LocalPlayer
};
var partyLobbyName = $"{k_LobbyNamePrefix}_{m_LocalPlayer.Id}";
m_PartyLobby = await LobbyService.Instance.CreateLobbyAsync(partyLobbyName,
m_MaxPartyMembers,
partyLobbyOptions);
await OnJoinedParty(m_PartyLobby);
}
catch (LobbyServiceException e)
{
PopUpLobbyError(e);
}
}
Assign another player as the party lead (as the party lead)
async Task TrySetHost(string playerId)
{
if (!m_LocalPlayer.IsHost)
return;
try
{
var setHostOptions = new UpdateLobbyOptions()
{
HostId = playerId
};
await LobbyService.Instance.UpdateLobbyAsync(m_PartyLobby.Id, setHostOptions);
}
catch (LobbyServiceException e)
{
PopUpLobbyError(e);
}
Invite players to / Join a party
You need to create a method for sending invites to players. However, in lieu of the ability to send invites to players, players can share the LobbyCode via text communication.
async void TryLobbyJoin(string joinCode)
{
try
{
var joinOptions = new JoinLobbyByCodeOptions()
{
Player = m_LocalPlayer
};
m_PartyLobby = await LobbyService.Instance.JoinLobbyByCodeAsync(joinCode, joinOptions);
await OnJoinedParty(m_PartyLobby);
}
catch (LobbyServiceException e)
{
var joinFailMessage = FormatLobbyError(e);
m_LobbyJoinPopupPopupView.JoinPartyFailed(joinFailMessage);
}
}
Leave a party
async void OnLeaveLobby()
{
await RemoveFromParty(m_LocalPlayer.Id);
NotificationEvents.onNotify?.Invoke(
new NotificationData(
"You", "Left the Party!", 1));
//Leave Lobby Regardless of result
OnLeftParty();
}
Remove a player from a party (as the party lead)
async Task RemoveFromParty(string playerID)
{
try
{
await LobbyService.Instance.RemovePlayerAsync(m_PartyLobby.Id, playerID);
}
catch (LobbyServiceException e)
{
PopUpLobbyError(e);
}
}
Visit the Support page to learn how to contact the Unity Lobby support team.