---
source_url: https://www.pubnub.com/docs/sdks/unity/api-reference/misc
title: Utility Methods API for Unity SDK
updated_at: 2026-06-19T11:38:54.283Z
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


# Utility Methods API for Unity SDK

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

The methods on this page are utility methods that don't fit into other categories.

## Cleanup

Cleanup frees up the threads and allows for clean exit.

### Method(s)

```csharp
Pubnub.CleanUp()
```

### Sample code

:::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;
using UnityEngine;

public class PubnubCleanupExample : MonoBehaviour {
	private void OnApplicationQuit() {
		// Performing cleanup operations
		Debug.Log("Cleaning up PubNub resources...");
		Pubnub.CleanUp();
		Debug.Log("Cleanup complete.");
	}
}
```

### Returns

None

## Disconnect

Call the `Disconnect` method to force the SDK to stop all requests to PubNub server when there are active subscribe channels.

### Method(s)

To `disconnect` the data transmission you can use the following method(s) in Unity SDK.

```csharp
Disconnect<T>()
```

This method doesn't take any arguments.

### Sample code

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

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

// Initialize PubNub
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;
*/

pubnub.Disconnect<string>();
```

## Get subscribed channel groups

Returns all the subscribed channel groups in a `List of type String`.

### Method(s)

To `Get Subscribe Channel Groups` you can use the following method(s) in the Unity SDK:

```csharp
List<string> GetSubscribedChannelGroups()
```

### Sample code

#### Get subscribed channel groups

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

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

// Initialize PubNub
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;
*/

List<string> groups = pubnub.GetSubscribedChannelGroups();
```

### Response

`List<String>`

```json
["channelGroup1", "channelGroup2"]
```

## Get subscribed channels

Returns all the subscribed channels in a `List of type String`.

### Method(s)

To `Get Subscribed Channels` you can use the following method(s) in the Unity SDK:

```csharp
List<string> GetSubscribedChannels()
```

### Sample code

#### Get subscribed channels

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

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

// Initialize PubNub
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;
*/

List<string> channels = pubnub.GetSubscribedChannels();
```

### Response

`List<String>`

```json
["channel1", "channel2"]
```

## Reconnect

Call the `reconnect` method to force the SDK to try and reach out PubNub.

### Method(s)

To `reconnect` the data you can use the following method(s) in Unity SDK.

```csharp
Reconnect<T>(bool resetSubscribeToken)
```

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| resetSubscribeToken | bool | Optional |  | Passing `true` will send zero timetoken upon reconnect. |

### Sample code

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

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

// Initialize PubNub
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;
*/

pubnub.Reconnect<string>();
```

## Create push payload

This method creates the push payload for use in the appropriate endpoint calls.

### Method(s)

```csharp
CreatePushPayloadHelper()
    .SetAPNSPayload(PNAPSData, List<PNAPNS2Data>)
    .SetFCMPayload(PNFCMData)
    .SetCommonPayload(Dictionary<string, object>)
    .BuildPayload()
```

| Parameter | Description |
| --- | --- |
| `SetAPNSPayload`Type: PNAPSData | Set APNS Payload. Associated APNS devices will receive only the data within the `pn_apns` key. |
| Type: `List<PNAPNS2Data>` | Set APNS2 Payload. Associated APNS devices will receive only the data within the `pn_push` key. |
| `SetFCMPayload`Type: PNFCMData | Set FCM Payload. Associated FCM devices will receive only the data within the `pn_fcm` key. |
| `SetCommonPayload`Type: `Dictionary<string, object>` | Set Common Payload. Native PubNub subscribers will receive the entire object literal, including the `pn_apns`, `pn_fcm`, and `common payload`. |
| `BuildPayload` *Type: | Builds the payload from the values set using the parameters. Returns a `Dictionary<string, object>` |

### Sample code

#### Create push payload

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

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

// Initialize PubNub
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;
*/
```

### Response

The `CreatePushPayloadHelper()` operation returns a `Dictionary<string, object>` which can be passed directly to the `Publish` Method's `Message` parameter.