---
source_url: https://www.pubnub.com/docs/chat/unity-chat-sdk/build/features/channels/leave
title: Leave channels
updated_at: 2026-06-19T11:35:21.347Z
---

> 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


# Leave channels

:::note Requires App Context
Enable [App Context](https://youtu.be/9UEoSlngpYI) for your keyset in the [Admin Portal](https://admin.pubnub.com/).
:::

Remove a user's channel membership with `LeaveChannel()`. The membership is deleted from App Context and other listeners receive a presence update.

:::warning Disconnect separately
`LeaveChannel()` only removes the membership. To stop receiving messages, call [Disconnect()](https://www.pubnub.com/docs/chat/unity-chat-sdk/build/features/channels/watch#unwatch-a-channel) separately.
:::

:::tip Method naming
Earlier versions used `Leave()` to destroy the membership and stop receiving messages in a single call. `LeaveChannel()` supersedes `Leave()` by separating membership removal from message unsubscription. `Leave()` remains available but is deprecated.
:::

## Method signature

This method has the following signature:

```csharp
channel.LeaveChannel()
```

### Input

This method doesn't take any parameters.

### Output

This method returns an awaitable `Task<ChatOperationResult>`.

## Sample code

Leave the `support` channel.

```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;
}
// reference the "channel" object
var channelResult = await chat.GetChannel("support");
if (channelResult.Error)
{
    Debug.Log("Couldn't find channel!");
    return;
}
var channel = channelResult.Result;

// note that this callback will only start firing if we call Connect() first
channel.OnMessageReceived += OnMessageReceivedHandler; // or use lambda
void OnMessageReceivedHandler(Message message)
{
    Debug.Log($"Message received: {message.MessageText}");
}
// join the channel to add metadata to the newly created membership
await channel.JoinChannel();
// and leave
await channel.LeaveChannel();
```