---
source_url: https://www.pubnub.com/docs/chat/unity-chat-sdk/build/features/messages/pinned
title: Pinned messages
updated_at: 2026-06-03T11:40:27.821Z
---

> 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


# Pinned messages

Pin messages to channels for easy access. Only one message can be pinned per channel at a time.

Use cases:

* Essential announcements and updates
* Action items and reminders
* Polls and persistent questions

:::note Requires App Context and Message Persistence
Enable [App Context](https://youtu.be/9UEoSlngpYI) and [Message Persistence](https://youtu.be/qLMtbINWGig) in the [Admin Portal](https://admin.pubnub.com/).
:::

## Pin

`Pin()` and `PinMessage()` attach a message to the channel.

Both of these methods give the same result. The only difference between them is that you may or may not be required to provide input parameters, and you call them on different objects: message (`Pin()`) or channel (`PinMessage()`).

Alternatively, you can also use other Unity Chat SDK methods to pin a message in a thread (thread message) to the [thread channel](https://www.pubnub.com/docs/chat/unity-chat-sdk/build/features/messages/threads#pin-thread-message-to-thread-channel) or the [parent channel](https://www.pubnub.com/docs/chat/unity-chat-sdk/build/features/messages/threads#pin-thread-message-to-parent-channel).

### Method signature

These methods take the following parameters:

* Pin() 1message.Pin()
* PinMessage() 1channel.PinMessage(Message message)

#### Input

| Parameter | Required in Pin() | Required in PinMessage() | Description |
| --- | --- | --- | --- |
| message | Message | Optional |  | No | Yes | [Message object](https://www.pubnub.com/docs/chat/unity-chat-sdk/learn/chat-entities/message) that you want to pin to the selected channel. |

#### Output

An awaitable `Task<ChatOperationResult>`.

### Sample code

Pin the last message on the `incident-management` channel.

* Pin() using System; using System.Linq; 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 the "incident-management" channel var channelResult = await chat.GetChannel("incident-management"); if (channelResult.Error) { Debug.Log("Incident-management channel not found."); return; } var channel = channelResult.Result; Debug.Log($"Found channel with name {channel.Name}"); // retrieve the message history with the desired count var messageHistoryResult = await channel.GetMessageHistory(null, null, 1); if (messageHistoryResult.Error) { Debug.Log("Could not retrieve message history."); return; } // get the last message from the returned list var lastMessage = messageHistoryResult.Result.FirstOrDefault(); // pin the last message if it exists if (lastMessage != null) { await lastMessage.Pin(); Debug.Log("Pinned the last message in the incident-management channel."); } else { Debug.Log("No messages found in the channel history."); }
* PinMessage() using System; using System.Linq; 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 the "incident-management" channel var channelResult = await chat.GetChannel("incident-management"); if (channelResult.Error) { Debug.Log("Incident-management channel not found."); return; } var channel = channelResult.Result; Debug.Log($"Found channel with name {channel.Name}"); // retrieve the message history with the desired count var messageHistoryResult = await channel.GetMessageHistory(null, null, 1); if (messageHistoryResult.Error) { Debug.Log("Could not retrieve message history."); return; } // get the last message from the returned list var lastMessage = messageHistoryResult.Result.FirstOrDefault(); // pin the last message using the PinMessage method if it exists if (lastMessage != null) { await channel.PinMessage(lastMessage); Debug.Log("Pinned the last message in the incident-management channel."); } else { Debug.Log("No messages found in the channel history."); }

## Get

`GetPinnedMessage()` fetches the message that is currently pinned to the channel.

### Method signature

```csharp
channel.GetPinnedMessage()
```

#### Input

This method doesn't take any parameters.

#### Output

| Parameter | Description |
| --- | --- |
| `Task<ChatOperationResult<Message>>`Type: `out Message` | An awaitable `Task` with the `Message` object if a pinned message exists, otherwise the `Error` property on the result will be `true`. |

#### Sample code

Get the message pinned to the `incident-management` channel.

```csharp
using System;
using System.Linq;
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;
}
var channelResult = await chat.GetChannel("incident-management");
if (channelResult.Error)
{
    Debug.Log("Channel 'incident-management' not found.");
    return;
}
var channel = channelResult.Result;
Debug.Log($"Found channel with name {channel.Name}");

// Try to get the pinned message from the channel
var pinnedMessageResult = await channel.GetPinnedMessage();
if (!pinnedMessageResult.Error)
{
    var pinnedMessage = pinnedMessageResult.Result;
    Debug.Log("Pinned message found: " + pinnedMessage.MessageText);
}
else
{
    Debug.Log("No pinned message found.");
}
```

## Unpin

`UnpinMessage()` unpins a message from the channel.

Alternatively, you can also use other Unity Chat SDK methods to unpin a message in a thread (thread message) from the [thread channel](https://www.pubnub.com/docs/chat/unity-chat-sdk/build/features/messages/threads#unpin-thread-message-from-thread-channel) or the [parent channel](https://www.pubnub.com/docs/chat/unity-chat-sdk/build/features/messages/threads#unpin-thread-message-from-parent-channel).

### Method signature

This method has the following signature:

```csharp
channel.UnpinMessage()
```

#### Input

This method doesn't take any parameters.

#### Output

An awaitable `Task<ChatOperationResult>`.

### Sample code

Unpin the message from the `incident-management` channel.

```csharp
using System;
using System.Linq;
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;
}
// attempt to get the channel named "incident-management"
var channelResult = await chat.GetChannel("incident-management");
if (!channelResult.Error)
{
    var channel = channelResult.Result;
    Debug.Log($"Found channel with name {channel.Name}");

    // attempt to unpin a message
    try
    {
        await channel.UnpinMessage();
        Debug.Log("Message has been unpinned successfully.");
    }
    catch (Exception ex)
    {
        Debug.Log($"Failed to unpin the message: {ex.Message}");
    }
}
else
{
    Debug.Log("Channel 'incident-management' not found.");
}
```