---
source_url: https://www.pubnub.com/docs/sdks/unity/api-reference/channel-groups
title: Channel Groups API for Unity SDK
updated_at: 2026-06-19T11:38:52.932Z
sdk_name: PubNub Unity SDK
sdk_version: v9.4.0
---

> 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


# Channel Groups API for Unity SDK

PubNub Unity SDK, use the latest version: v9.4.0

[Channel groups](https://www.pubnub.com/docs/general/channels/subscribe#channel-groups) allow PubNub developers to bundle thousands of [channels](https://www.pubnub.com/docs/general/channels/overview) into a group that can be identified by a name. These channel groups can then be subscribed to, receiving data from the many back-end channels the channel group contains.

:::note Channel group operations
You can't publish to a channel group. You can only subscribe to it. To publish within the channel group, you need to publish to each channel individually.
:::

## Add channels to a channel group

:::note Requires Stream Controller add-on
This method requires the *Stream Controller* add-on enabled for your key in the [Admin Portal](https://admin.pubnub.com/). Read the [support page](https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-) on enabling add-on features.
:::

This function adds a channel to a channel group.

### Method(s)

Use the following method in the Unity SDK:

:::note Maximum number of channels
You can add up to 200 channels to a channel group per API call.
:::

```csharp
pubnub.AddChannelsToChannelGroup()
    .ChannelGroup(string)
    .Channels(Array)
    .QueryParam(Dictionary<string,object>)
    .Execute(System.Action<PNChannelGroupsAddChannelResult, PNStatus>);
```

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| ChannelGroup | string | Yes |  | The `ChannelGroup` to add the channels to. |
| Channels | Array | Yes |  | The `Channels` to add to the channel group. |
| QueryParam | Dictionary<string, | Optional |  | Name-value pairs to include as query parameters. |
| Async | PNCallback | Optional |  | PNCallback of type PNChannelGroupsAddChannelResult. |
| Execute | System.Action | Yes |  | `System.Action` of type `PNChannelGroupsAddChannelResult`. |
| ExecuteAsync | None | Optional |  | Returns `Task<PNResult<PNChannelGroupsAddChannelResult>>`. |

### Sample code

#### Add channels

:::tip Reference code
This example is a self-contained code snippet ready to be run. It includes necessary imports and executes methods with console logging. Use it as a reference when working with other examples in this document.
:::

```csharp
using PubnubApi.Unity;
using UnityEngine;

public class AddChannelsToGroupExample : MonoBehaviour {
	// Reference to a pubnub manager previously setup in Unity Editor
	// For more details, see https://www.pubnub.com/docs/sdks/unity#configure-pubnub
	[SerializeField] private PNManagerBehaviour pubnubManager;

	// An editor-serialized string for the channel group ID
	[SerializeField] private string channelGroupId = "cg1";

	// An editor-serialized array for the channels to add
	[SerializeField] private string[] channelsToAdd = { "ch1", "ch2", "ch3" };

	private async void Start() {
		// Getting a reference to the Pubnub instance
		var pubnub = pubnubManager.pubnub;

		// Note that you can also initialize Pubnub instance for Unity directly from code:
		/*
		PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId"))
		{
			SubscribeKey = "demo",
			PublishKey = "demo",
		};
		Pubnub pubnub = PubnubUnityUtils.NewUnityPubnub(pnConfiguration);
		*/

		// Adding channels to the specified channel group
		var cgAddChResponse = await pubnub.AddChannelsToChannelGroup()
			.ChannelGroup(channelGroupId)
			.Channels(channelsToAdd)
			.ExecuteAsync();

		// Checking the status of the operation
		var status = cgAddChResponse.Status;
		if (status.Error) {
			Debug.LogError($"Error adding channels to group: {status.ErrorData.Information}");
		} else {
			Debug.Log($"Successfully added channels to group {channelGroupId}");
		}
	}
}
```

### Returns

The `AddChannelsToChannelGroup()` operation returns a `PNResult<PNChannelGroupsAddChannelResult>` with:

| Property Name | Type | Description |
| --- | --- | --- |
| `Result` | PNChannelGroupsAddChannelResult | The operation result. |
| `Status` | PNStatus | The request status. |

`PNChannelGroupsAddChannelResult` includes:

| Property Name | Type | Description |
| --- | --- | --- |
| `PNChannelGroupsAddChannelResult` | Object | Empty object. |
| `PNStatus` | Object | Request status, including errors. |

## List channels in a channel group

:::note Requires Stream Controller add-on
This method requires the *Stream Controller* add-on enabled for your key in the [Admin Portal](https://admin.pubnub.com/). Read the [support page](https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-) on enabling add-on features.
:::

This function lists all channels in a channel group.

### Method(s)

Use the following method in the Unity SDK:

```csharp
pubnub.ListChannelsForChannelGroup()
    .ChannelGroup(string)
    .QueryParam(Dictionary<string,object>)
    .Execute(System.Action<PNChannelGroupsAllChannelsResult, PNStatus>);
```

| Parameter | Description |
| --- | --- |
| `ChannelGroup` *Type: string | The channel group to fetch the channels of. |
| `QueryParam`Type: Dictionary`<string, object>` | Name-value pairs to include as query parameters. |
| AsyncType: PNCallback | PNCallback of type PNChannelGroupsAllChannelsResult. |
| `Execute` *Type: `System.Action` | `System.Action` of type `PNChannelGroupsAllChannelsResult`. |
| `ExecuteAsync`Type: None | Returns `Task<PNResult<PNChannelGroupsAllChannelsResult>>`. |

### Sample code

#### List channels

```csharp
using PubnubApi;
using PubnubApi.Unity;

//Create configuration
PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId"))
{
    SubscribeKey = "demo",
    PublishKey = "demo"
};
//Create a new PubNub instance
Pubnub pubnub = PubnubUnityUtils.NewUnityPubnub(pnConfiguration);

// If you're using Unity Editor setup you can get the Pubnub instance from PNManagerBehaviour
// For more details, see https://www.pubnub.com/docs/sdks/unity#configure-pubnub
/*
[SerializeField] private PNManagerBehaviour pubnubManager;
Pubnub pubnub = pubnubManager.pubnub;
*/

PNResult<PNChannelGroupsAllChannelsResult> cgListChResponse = await pubnub.ListChannelsForChannelGroup()
    .ChannelGroup("cg1")
    .ExecuteAsync();
```

### Returns

The `ListChannelsForChannelGroup()` operation returns a `PNChannelGroupsAllChannelsResult` with:

| Property Name | Type | Description |
| --- | --- | --- |
| `Result` | PNChannelGroupsAllChannelsResult | The operation result. |
| `Status` | PNStatus | The request status. |

`PNChannelGroupsAllChannelsResult` includes:

| Property Name | Type | Description |
| --- | --- | --- |
| `Channels` | List`<string>` | Channel names in the group. |

## Remove channels from a channel group

:::note Requires Stream Controller add-on
This method requires the *Stream Controller* add-on enabled for your key in the [Admin Portal](https://admin.pubnub.com/). Read the [support page](https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-) on enabling add-on features.
:::

This function removes channels from a channel group.

### Method(s)

Use the following method in the Unity SDK:

```csharp
pubnub.RemoveChannelsFromChannelGroup()
    .ChannelGroup(string)
    .Channels(Array)
    .QueryParam(Dictionary<string,object>)
    .Execute((result, status) => {});
```

| Parameter | Description |
| --- | --- |
| `ChannelGroup` *Type: string | The channel group to remove channels from. |
| `Channels` *Type: Array | The channels to remove. |
| `QueryParam`Type: Dictionary`<string, object>` | Name-value pairs to include as query parameters. |
| AsyncType: PNCallback | PNCallback of type PNChannelGroupsRemoveChannelResult. |
| `Execute` *Type: `System.Action` | `System.Action` of type `PNChannelGroupsRemoveChannelResult`. |
| `ExecuteAsync`Type: None | Returns `Task<PNResult<PNChannelGroupsRemoveChannelResult>>`. |

### Sample code

#### Remove channels

```csharp
using PubnubApi;
using PubnubApi.Unity;

//Create configuration
PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId"))
{
    SubscribeKey = "demo",
    PublishKey = "demo"
};
//Create a new PubNub instance
Pubnub pubnub = PubnubUnityUtils.NewUnityPubnub(pnConfiguration);

// If you're using Unity Editor setup you can get the Pubnub instance from PNManagerBehaviour
// For more details, see https://www.pubnub.com/docs/sdks/unity#configure-pubnub
/*
[SerializeField] private PNManagerBehaviour pubnubManager;
Pubnub pubnub = pubnubManager.pubnub;
*/

PNResult<PNChannelGroupsRemoveChannelResult> rmChFromCgResponse = await pubnub.RemoveChannelsFromChannelGroup()
    .ChannelGroup("family")
    .Channels(new string[] {
        "son"
    })
    .ExecuteAsync();
```

### Returns

The `RemoveChannelsFromChannelGroup()` operation returns a `PNChannelGroupsAddChannelResult` with:

| Property Name | Type | Description |
| --- | --- | --- |
| `Result` | PNChannelGroupsRemoveChannelResult | The operation result. |
| `Status` | PNStatus | The request status. |

`PNChannelGroupsRemoveChannelResult` includes:

| Property Name | Type | Description |
| --- | --- | --- |
| `PNChannelGroupsRemoveChannelResult` | Object | Empty object. |

## Delete a channel group

:::note Requires Stream Controller add-on
This method requires the *Stream Controller* add-on enabled for your key in the [Admin Portal](https://admin.pubnub.com/). Read the [support page](https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-) on enabling add-on features.
:::

This function removes a channel group.

### Method(s)

Use the following method in the Unity SDK:

```csharp
pubnub.DeleteChannelGroup()
    .ChannelGroup(string)
    .QueryParam(Dictionary<string,object>)
    .Execute(System.Action<PNChannelGroupsDeleteGroupResult, PNStatus>);
```

| Parameter | Description |
| --- | --- |
| `ChannelGroup` *Type: string | The channel group to remove. |
| `QueryParam`Type: Dictionary`<string, object>` | Name-value pairs to include as query parameters. |
| AsyncType: PNCallback | PNCallback of type PNChannelGroupsDeleteGroupResult. |
| `Execute` *Type: `System.Action` | `System.Action` of type `PNChannelGroupsDeleteGroupResult`. |
| `ExecuteAsync`Type: None | Returns `Task<PNResult<PNChannelGroupsDeleteGroupResult>>`. |

### Sample code

#### Delete channel group

```csharp
using PubnubApi;
using PubnubApi.Unity;

//Create configuration
PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId"))
{
    SubscribeKey = "demo",
    PublishKey = "demo"
};
//Create a new PubNub instance
Pubnub pubnub = PubnubUnityUtils.NewUnityPubnub(pnConfiguration);

// If you're using Unity Editor setup you can get the Pubnub instance from PNManagerBehaviour
// For more details, see https://www.pubnub.com/docs/sdks/unity#configure-pubnub
/*
[SerializeField] private PNManagerBehaviour pubnubManager;
Pubnub pubnub = pubnubManager.pubnub;
*/

PNResult<PNChannelGroupsDeleteGroupResult> delCgResponse = await pubnub.DeleteChannelGroup()
    .ChannelGroup("family")
    .ExecuteAsync();
```

### Returns

The `DeleteChannelGroup()` operation returns a `PNResult<PNChannelGroupsDeleteGroupResult>` with:

| Property Name | Type | Description |
| --- | --- | --- |
| `Status` | int | HTTP status code. |
| `Error` | bool | True if the operation failed. |

```json
{
    "status" : 200,
    "message" : "OK",
    "service" : "channel-registry",
    "error" : False
}
```