View as Markdown

Real-time Parties

Real-time parties is a great way to add team play to a game, enabling users to form a party and communicate with party members.

A party is a group of users who’ve gathered together to participate in some kind of gameplay or social gathering. Any user can create a party and will become the initial party leader. Users can invite other players to join or can mark the party as private so other players must request to join. A leader is always required and selected from players who are currently connected when the current leader leaves. When all players leave the party it’s gone.

A very common Nakama-supported use case for parties is to matchmake together in groups. This suits gameplay where users collaborate in squads, or where players compete in team battles. The matchmaker can be passed a party ID which instructs the matching logic to ensure that enough capacity is reserved to join the match altogether.

Parties differ from the groups feature because they’re not designed to exist between play sessions when the user goes offline. A party only exists as long as at least one user is in it. You should use groups if you want to create guild systems or other gameplay which should exist as a persistent entity in your game or apps.

Create party #

A party can be created by any user. Limit the max number of users in the party (up to 256) and choose whether members need the leader’s approval to join. Assign an optional JSON label to make the party discoverable via party search. Party labels use the same format and query syntax as match labels. Set hidden to true to keep the party out of search results. Hidden parties can’t have a label.

You can create rules on which users can create parties in your game with before hooks using runtime code.

Update party #

Update the party’s label, open status, and hidden flag at any time. Only the party leader can make changes. All party members receive a ReceivedPartyUpdate event when an update occurs.

Find party #

After creating a new party, make it discoverable through party search or share the party ID directly via Nakama’s social features:

The way you combine these features of the server to power your game design can create wonderful social mechanics to bring users together and create a deep and meaningful player community.

With the party ID, users can then join the party.

Search parties #

Discover open parties by searching their labels. Only parties with hidden: false appear in results. Calling the List API with an empty query returns all non-hidden parties, including those with no label. Party labels are JSON objects that use the same query syntax as match listing.

Access the party listing API from server runtime code:

Use before and after hooks to add custom logic around party listing:

To filter by player count, include the current member count in the party label. The party leader must call update party each time a player joins or leaves to keep the label in sync, which lets you pass a range filter like +label.player_count:<10 to return only parties with available slots.

Join party #

A user must join a party before they can send messages, see the member list, or invite other users.

If the party is private, users can request to join and the party leader can accept or reject.

Leave party #

A user can leave a party at any time. The user will also be automatically removed from the party if they disconnect from the server.

Party leader rotation #

When a user leaves the server will check whether they are the current party leader and, if they were, send a message to indicate the leader has left and which member was promoted as the new party leader.

When an automated promotion happens the leader chosen will always be the user who has been part of the party for the longest since it was created. This is a deterministic process and cannot be changed. See manual leader promotion if your game needs different criteria to promote a new leader.

Send messages #

Any user who is a party member can send messages to the party containing: text, emotes, or game specific actions.

Manual leader promotion #

As well as regular messages the party leader can also send a special promotion message which will declare that they’ve stepped down as the current leader and who they have promoted to the new leader.

Close party #

A party cannot be closed by any member other than the party leader. The party leader can also eject all party members, which will close the party and clear its state on the server. In most cases it’s more useful from a game design perspective to allow the leader to leave.

Best practices #

We recommend you don’t use parties to implement multiplayer game logic or use it for scenarios where the messages sent to the party members is intended to drive gameplay progression. In these cases it’s better to use the authoritative multiplayer engine in the game backend. This gives you complete control over your multiplayer net code and the logic associated with actions taken by users.