---
updatedAt: 2025-11-11T17:56:07.000Z
agentTools:
  projectIndex: https://beamable2.readme.io/llms.txt
---

# Parties - Code

[SOCL-Parties-03]

<ul class="breadcrumb">
  <li><a href="/docs/">Docs</a></li>
  <li><a href="/docs/social-networking">Social & Networking</a></li>
  <li><a href="/docs/parties-feature-overview">Parties</a></li>
  <li>Parties - Code</li>
</ul>

<div class="links">
  <a class="link normal" href="/docs/parties-feature-overview" style={{textDecoration: 'none'}}>Overview</a>
  {/*  */}
  <a class="link active" href="/docs/parties-code" style={{textDecoration: 'none'}}>Code</a>
</div>

***

## Examples

​\
These examples cover common use cases for Parties. The `_beamContext` variable used below is an instance of the `BeamContext` class may be obtained by `BeamContext.Default`:

​

### Create Party

​\
The `Create` method will fill the state of a current party which can be accessed through `_beamContext.Party.State`.\
The `Create` method has a number of optional parameters:

* `maxSize` determines maximum allowed number of players in the party. 0 means default value which is currently defined by the backend and is equal to 25.
* callbacks for party related events which can be provided later through subscriptions.
* `PartyRestriction` has 2 possible values:
  * `Unrestricted` means the party can be joined by any player who knows the `partyId`
  * `InviteOnly` allows only invited players to join the party

```csharp
await _beamContext.Party.Create(PartyRestriction.Unrestricted);
```

### Listen for Party Updates

​\
The following events are available

```csharp
		public Action<PartyInviteNotification> OnPlayerInvited;
		public Action<PlayerJoinedNotification> OnPlayerJoined;
		public Action<PlayerLeftNotification> OnPlayerLeft;
		public Action<PartyUpdatedNotification> OnPartyUpdated;
		public Action<PlayerPromotedNotification> OnPlayerPromoted;
		public Action<PlayerKickedNotification> OnPlayerKicked;
```

### Join Party

```csharp
await _beamContext.Party.Join(partyId);
```

​

### Leave Party

```csharp
await _beamContext.Party.Leave();
```

### Get Party Invites

There is an observable list of available party invites.

```csharp
party.ReceivedPartyInvites.OnElementsAdded += invites =>
{
	// accept the first invite
	invites.First().Accept();
};

```

Additionally, this method returns a `InvitesResponse` object which contains pending party invitations as `List<PartyInvite>`. Each `PartyInvite` contains a `invitedBy` player ID and a `partyId` which can be passed to `Party.Join` method to join the party.

```csharp
var invites = await _beamContext.Party.GetInvites();
```

## Party Leader Methods

​\
Methods below can be called only by a party leader.\
​

### Update Party

​\
This method allows to change settings of an already created party. Again `maxSize` parameter is optional. The `State` property is altered by this method.

```csharp
await _beamContext.Party.Update(PartyRestriction.Unrestricted, 5);
```

### Invite Player

```csharp
// acquire a playerId from the player social sdk
await _beamContext.Party.Invite(playerId);
```

### Party Member Actions

There is an observable structure, `PartyMembers` that contains the list of party members. If the current player is the leader, they can promote or kick players from this list.

```
party.PartyMembers.OnElementsAdded += members =>
{
	foreach (var member in members)
	{
		Debug.Log($"{member.playerId} joined the party");
	}
};


party.PartyMembers.OnElementRemoved += members =>
{
	foreach (var member in members)
	{
		Debug.Log($"{member.playerId} left the party");
	}
};
```

The `PartyMember` structure has `Promote` and `Kick` methods, but player actions can also be taken with the `Party` accessor directly.

```csharp

// promote the player to party leader
await _beamContext.Party.Promote(playerId);

// remove the player from the party
await _beamContext.Party.Kick(playerId);
```

​

# FAQ

​

* Is there a party storage? Similar to `clientData` in `GroupService` that we can utilize?\
  ​\
  There is no such storage. All the data related to parties is stored in `_beamContext.Party.State`. The only properties you can change are `restriction` which is either `PartyRestriction.Unrestricted` or `PartyRestriction.InviteOnly` and `maxSize`. To alter them you need to call `Update` method as a party leader.\
  ​
* Is there any method / way to disband the party?\
  ​\
  The party is disbanded automatically when all of the members leave. When a leader leaves the party a new one is chosen automatically.\
  ​
* What is the difference between `Party.State` vs `Party.Value` ?\
  ​\
  Both properties point to the same object. However `Party.Value` is obsolete.\
  ​
* Is `Party.State` / `Party.Value` automatically updated if there is a change in party data? (new member join, owner change, etc). I found that we can also get Party data directly from `Party`, ex: `Party.Id`, `Party.Members`, `Party.Leader`.\
  Members data is `List<string>`. Are those string values userIds? Why string not long? What is the difference between userId (long) vs playerId (string)?\
  ​\
  Yes, party data gets updated automatically based on notifications. Properties like `Party.Id` are just a shorthand for `Party.State.Id`.\
  Use the `PartyMember` observable list to get access to the list of party members instead of the obsolete `Member` list. `PartyMember` instances have `long` userId types instead of `string`.

<HTMLBlock>{`
<style>
  .links {
    padding: 0 1em 1em 0;
    display: flex;
    flex-flow: row wrap;
  }

  .link {
    margin-right: 2em;
    padding: 0.3em 1.5em;
    box-sizing: border-box;
  }

  .active {
    border: 1px solid #4274f6;
    background-color: #4274f6;
    color: white;
  }

  .normal {
    background-color: white;
    border: 1px solid gray;
    cursor:pointer;
    text-decoration: none;
  }

  .normal:active {
    background-color: #c4d4ff;
  }

  .normal:hover {
    background-color: #c4d4ff;
  }

  .active:active {
    color: white;
  }

  .active:hover {
    color: white;
  }
  
  ul.breadcrumb {
    padding: 10px 16px;
    list-style: none;
  }
  ul.breadcrumb li {
    display: inline;
    font-size: 18px;
  }
  ul.breadcrumb li+li:before {
    padding: 8px;
    color: black;
    content: "/\\00a0";
  }
  ul.breadcrumb li a {
    color: #0275d8;
    text-decoration: none;
  }
  ul.breadcrumb li a:hover {
    color: #01447e;
    text-decoration: underline;
  }
  
        @media only screen and (max-width:700px){
 		    ul.breadcrumb {
    padding-top:0;
          padding-left:0;
  }
      
       .link {
    margin-right: 1em;
         margin-bottom:1em;
  }
  }
</style>
`}</HTMLBlock>