> ## Documentation Index
> Fetch the complete documentation index at: https://docs.qwacks.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Parties

> Friends who stay together from one game to the next.

A **party** is a group of friends who play together: one leader and up to 63 others. A party lasts
until its players leave it, across games and launches, so friends can play match after match
without inviting each other again. Friends join with the party's **invite code**. A player is in
one party at a time.

> [!NOTE]
>
> **Scope:** parties belong to the players in them, within one **game**.

**Dashboard**

There is nothing to set up. A party searching for a match shows on
**Multiplayer → Matchmaking Activity** as one entry, with its size.

**Unity**

Read the party after signing in: the player may still be in one from last time.

```csharp theme={null}
FlockMultiplayerProvider multiplayer = FlockClient.Instance.Multiplayer;

// The party from last time, or a new one: 2 to 64 players, 4 when not given.
FlockParty party = await multiplayer.GetMyPartyAsync()
    ?? await multiplayer.CreatePartyAsync(4, new Dictionary<string, object> { ["mode"] = "coop" });
inviteCodeLabel.text = party.InviteCode;

party.MembersChanged += () => ShowMembers(party.Members);   // in the order they joined
party.LeaderChanged += () => leaderControls.SetActive(party.IsLeader);
party.Ended += reason => ShowMainMenu(reason);
```

A friend's game joins with the code; letter case does not matter.

```csharp theme={null}
FlockParty joined = await multiplayer.JoinPartyAsync(typedCode);
if (joined.TryGetSetting("mode", out string mode))
    ShowMode(mode);
```

The leader manages the party; anyone can leave it.

```csharp theme={null}
await party.UpdateAsync(settings: new Dictionary<string, object> { ["mode"] = "hard" });   // replaces all settings
await party.KickAsync(playerId);
await party.MakeLeaderAsync(playerId);
await party.DisbandAsync();

await party.LeaveAsync();   // when the leader leaves, the first of the others leads
```

`party.FindMatchAsync` searches as the party; see [Matchmaking](/guides/matchmaking.md).

**Unreal**

Read the party after signing in: the player may still be in one from last time. The examples
run in your game instance; every call is on `UFlockSubsystem::GetMultiplayerProvider()`, made
from the game thread.

```cpp theme={null}
#include "FlockSubsystem.h"
#include "Multiplayer/FlockParty.h"

// The party from last time, or a new one: 2 to 64 players, 4 when unset.
GetSubsystem<UFlockSubsystem>()->GetMultiplayerProvider()->GetMyParty([this](TFlockResult<UFlockParty*> Mine)
{
    if (!Mine.IsSuccess())
    {
        UE_LOG(LogTemp, Warning, TEXT("%s"), *Mine.Error.ToDisplayText());   // what went wrong, then its fix
    }
    else if (Mine.Value != nullptr)
    {
        HoldParty(Mine.Value);
    }
    else
    {
        GetSubsystem<UFlockSubsystem>()->GetMultiplayerProvider()->CreateParty(4,
            FFlockCommandData().Set(TEXT("mode"), TEXT("coop")),
            [this](TFlockResult<UFlockParty*> Made) { if (Made.IsSuccess()) { HoldParty(Made.Value); } });
    }
});

void UMyGameInstance::HoldParty(UFlockParty* InParty)
{
    Party = InParty;   // a UPROPERTY
    ShowInviteCode(Party->GetInviteCode());
    Party->OnMembersChanged.AddDynamic(this, &UMyGameInstance::ShowMembers);         // GetMembers(): in the order they joined
    Party->OnLeaderChanged.AddDynamic(this, &UMyGameInstance::ShowLeaderControls);   // IsLeader()
    Party->OnEnded.AddDynamic(this, &UMyGameInstance::ShowMainMenu);                 // ShowMainMenu(EFlockPartyEndReason Reason)
}
```

A friend's game joins with the code; letter case does not matter.

```cpp theme={null}
GetSubsystem<UFlockSubsystem>()->GetMultiplayerProvider()->JoinParty(TypedCode, [this](TFlockResult<UFlockParty*> Joined)
{
    FString Mode;
    if (Joined.IsSuccess() && Joined.Value->GetSettings().TryGetString(TEXT("mode"), Mode))
    {
        ShowMode(Mode);
    }
});
```

The leader manages the party; anyone can leave it. Each call completes with the party as it
stands afterwards.

```cpp theme={null}
Party->Update(TOptional<int32>(), FFlockCommandData().Set(TEXT("mode"), TEXT("hard")), nullptr);   // replaces all settings
Party->Kick(PlayerId, nullptr);
Party->MakeLeader(PlayerId, nullptr);
Party->Disband(nullptr);

Party->Leave(nullptr);   // when the leader leaves, the first of the others leads
```

Every call returns an `FFlockRequestHandle`; its `Cancel()` stops the request on its way. A call
on a party that has ended is refused (`Validation`) without a request. `Party->FindMatch`
searches as the party; see [Matchmaking](/guides/matchmaking.md).

In Blueprint, the calls are nodes under **Flock | Multiplayer**: **Flock Create Party** and
**Flock Join Party** (On Success with the party, On Failure with the error), **Flock Get My
Party** (On Party, On No Party, On Failure), and **Flock Leave Party**, **Flock Kick From
Party**, **Flock Make Party Leader**, **Flock Update Party** and **Flock Disband Party**. Bind
the party's **On Members Changed**, **On Leader Changed** and **On Ended** events on the party
object.

## Keeping the party current

The SDK reads the party every **Party Refresh Seconds** (10 by default) and after each change your
game makes, and raises `MembersChanged` and `LeaderChanged` (`OnMembersChanged` and
`OnLeaderChanged` on Unreal) when something moved. Another player's change reaches your game by
the next read. These reads are not billed; see
[Multiplayer](/guides/multiplayer.md#what-counts-as-an-api-call).

## When the party ends

`Ended` (`OnEnded` on Unreal) is raised once, with a reason: a `FlockPartyEndReason` on Unity, an
`EFlockPartyEndReason` on Unreal, with the same names.

| Reason | When |
| - | - |
| `Left` | The player left with `LeaveAsync` (Unreal: `Leave`). |
| `Disbanded` | The player disbanded it. |
| `Removed` | The server no longer lists the player: removed by the leader, the party disbanded by someone else, or the player left from another device. |
| `SignedOut` | The player signed out, or another player signed in. The player is still in the party on the server, so the next sign-in finds it again. |

Call `LeaveAsync` (Unreal: `Leave`) before signing out when the player means to leave.

## Errors

Each code is a `FlockErrorCode` on Unity and an `EFlockErrorCode` on Unreal, with the same name,
and the error carries a hint naming the fix.

| `ErrorCode` | When | What to do |
| - | - | - |
| `PartyInvalidInviteCode` | No open party has that code. | Ask the leader for the current code. |
| `PartyFull` | The party has no room, or a new size is below the players already in it. | Join another party, or the leader raises the size. |
| `PartyAlreadyInParty` | The player is in another party. | Read it (`GetMyPartyAsync`, or `GetMyParty` on Unreal) and leave it first. |
| `PartyNotPartyLeader` | A call only the leader can make. | Read the party again to see who leads now. |
| `PartyCannotKickLeader` | The leader tried to remove themselves. | Hand the lead to another player and then leave, or disband the party. |
| `PartyTargetNotAMember` | That player is not in the party. | Pick a player from the party's members. |
| `PartyNotFound` | The party is gone for this player: disbanded, or the player was removed. | The SDK ends the party as `Removed`; read the player's party again. |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.