---
source_url: https://www.pubnub.com/docs/chat/unity-chat-sdk/learn/chat-entities/membership
title: Membership object
updated_at: 2026-05-22T11:04:40.482Z
---

> Documentation Index
> For a curated overview of PubNub documentation, see: https://www.pubnub.com/docs/llms.txt
> For the full list of all documentation pages, see: https://www.pubnub.com/docs/llms-full.txt


# Membership object

`Membership` represents a single user-channel relationship in a chat.

## Properties

`Membership` has the following properties:

```csharp
public class Membership : UniqueChatEntity {
    public string Id { get; protected set; }
    public string UserId { get; }
    public string ChannelId { get; }
    public string LastReadMessageTimeToken { get; }
    public ChatMembershipData MembershipData { get; private set; }
}
```

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| Id | string | Optional |  | Unique identifier for the membership which is a combination of `UserId` and `ChannelId`. |
| UserId | string | Optional |  | The user ID of the user that this membership belongs to. |
| ChannelId | string | Optional |  | The channel ID of the channel that this membership belongs to. |
| LastReadMessageTimeToken | string | Optional |  | The string time token of last read message on the membership channel. |
| MembershipData | ChatMembershipData | Optional |  | Contains all the additional data related to the chat membership, including custom data, status, and type. |

### ChatMembershipData

The `ChatMembershipData` object contains the following properties:

| Parameter | Description |
| --- | --- |
| `CustomData`Type: `Dictionary<string, object>` | Any custom properties or metadata associated with the channel-user membership. |
| `Status`Type: `string` | Current status of the membership. When a user is [invited](https://www.pubnub.com/docs/chat/unity-chat-sdk/build/features/channels/invite) to a channel, the status is set to `"pending"`. When the user [joins](https://www.pubnub.com/docs/chat/unity-chat-sdk/build/features/channels/join) the channel, the status changes to an active state (empty string by default). |
| `Type`Type: `string` | Type of the membership. Can be used to categorize or classify different membership relationships. |

:::tip API limits
To learn about the maximum length of parameters used to set channel membership metadata, refer to [REST API docs](https://www.pubnub.com/docs/sdks/rest-api/set-membership-metadata).
:::

### Events

The `Membership` object has the following events:

```csharp
// Event triggered when user-channel membership is updated.
// Call StreamUpdates(true) to enable this callback.
public event Action<Membership> OnUpdated;
// Event triggered when the membership is hard-deleted from App Context.
// Call StreamUpdates(true) to enable this callback.
public event Action OnDeleted;
```

#### Example

An event that is triggered when user-channel membership is updated by the server.

```csharp
using System.Threading.Tasks;
using PubnubApi;
using PubnubChatApi;
using UnityEngine;

// Configuration
PubnubChatConfig chatConfig = new PubnubChatConfig();
        
PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId"))
{
    SubscribeKey = "demo",
    PublishKey = "demo",
    Secure = true
};

// Initialize Unity Chat
var chatResult = await UnityChat.CreateInstance(chatConfig, pnConfiguration);
if (!chatResult.Error)
{
    chat = chatResult.Result;
}
// Get user memberships
var membershipsResult = await chat.GetUserMemberships("myUniqueUserId");
if (!membershipsResult.Error && membershipsResult.Result.Memberships.Count > 0)
{
    var membership = membershipsResult.Result.Memberships[0];
            
    membership.OnUpdated += (membership) =>
    {
        Debug.Log("Membership metadata updated!");
    };
}
```

## Methods

You can call the following methods on the `Membership` object.

Click on each method for more details.

### Standard methods

* [Delete()](https://www.pubnub.com/docs/chat/unity-chat-sdk/build/features/channels/membership#delete)
* [GetUnreadMessagesCount()](https://www.pubnub.com/docs/chat/unity-chat-sdk/build/features/messages/unread#get-unread-messages-count-one-channel)
* [LastReadMessageTimeToken](https://www.pubnub.com/docs/chat/unity-chat-sdk/build/features/messages/unread#get-last-read-message)
* [SetLastReadMessage()](https://www.pubnub.com/docs/chat/unity-chat-sdk/build/features/messages/unread#mark-messages-as-read-one-channel)
* [SetLastReadMessageTimeToken()](https://www.pubnub.com/docs/chat/unity-chat-sdk/build/features/messages/unread#mark-messages-as-read-one-channel)
* [Update()](https://www.pubnub.com/docs/chat/unity-chat-sdk/build/features/channels/membership#update)

### Streaming methods

These methods register or unregister real-time event subscriptions. Each streaming method activates one or more of the events listed in the [Events](#events) section above.

* [StreamUpdates()](https://www.pubnub.com/docs/chat/unity-chat-sdk/build/features/channels/membership#get-updates)
* [StreamUpdatesOn()](https://www.pubnub.com/docs/chat/unity-chat-sdk/build/features/channels/membership#get-updates)

## Use case

`Membership` methods enable:

* [Updating](https://www.pubnub.com/docs/chat/unity-chat-sdk/build/features/channels/membership#update) user-channel relationships and [getting updates](https://www.pubnub.com/docs/chat/unity-chat-sdk/build/features/channels/membership#get-updates) on changes
* [Deleting](https://www.pubnub.com/docs/chat/unity-chat-sdk/build/features/channels/membership#delete) user-channel relationships
* Tracking the [last message read](https://www.pubnub.com/docs/chat/unity-chat-sdk/build/features/messages/unread#mark-messages-as-read-one-channel) by a user on a channel
* Getting the count of [unread messages](https://www.pubnub.com/docs/chat/unity-chat-sdk/build/features/messages/unread#get-unread-messages-count-one-channel) for a user