---
source_url: https://www.pubnub.com/docs/chat/unreal-chat-sdk/build/features/messages/pinned
title: Pinned messages
updated_at: 2026-05-22T11:04:43.702Z
---

> 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.

##### Usage in Blueprints and C++

You can use PubNub's functionality via Blueprints or directly in C++ code.

* In Blueprints, you can access PubNub from any Widget or Actor. Start by [initializing chat](https://www.pubnub.com/docs/chat/unreal-chat-sdk/build/configuration#initialize-pubnub-chat) using `InitChat` on `UPubnubChatSubsystem`. Afterwards, you can use the returned `UPubnubChat` object reference to call all Chat SDK functions.

:::warning Blueprint functions
The Blueprints provided in the documentation show how you can structure your application and may contain utility methods and elements like buttons that are not part of the Unreal Chat SDK and are meant to serve as guidance.
:::

* In C++, you can use UPubnubChatSubsystem as any other Game Instance Subsystem. #include "Kismet/GameplayStatics.h" #include "Engine/GameInstance.h" #include "PubnubChatSubsystem.h" // ACTION REQUIRED: Replace ASample_ChatSubsystem with name of your Actor class void ASample_ChatSubsystem::InitChatSample() { // Get PubnubChatSubsystem from GameInstance UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this); UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>(); // Initialize Chat - InitChat may fail under some conditions so make sure to check the Result for errors before using the Chat FPubnubChatInitChatResult InitChatResult = PubnubChatSubsystem->InitChat(TEXT("demo"), TEXT("demo"), TEXT("Player_001")); UPubnubChat* PubnubChat = InitChatResult.Chat; } Chat now allows you to call all Chat SDK functions, for example, Chat->GetChannel("my_channel").

:::note Asynchronous and synchronous method execution
Most PubNub Unreal SDK methods are available in both asynchronous and synchronous variants.
* Asynchronous methods (Async suffix) return void and take an optional delegate parameter that fires when the operation completes. 1Channel->PinMessageAsync(Message, OnPinMessageResponseDelegate); You can also use native callbacks that accept lambdas instead of dynamic delegates. Native callback types have the Native suffix (for example, FOnPubnubChatOperationResponseNative).
* Synchronous methods (no suffix) block the main game thread until the operation completes and return a result struct directly. 1FPubnubChatOperationResult Result = Channel->PinMessage(Message);
:::

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 a channel. Call `Pin()` on a message object or `PinMessage()` on a channel object.

Alternatively, pin thread messages to the [parent channel](https://www.pubnub.com/docs/chat/unreal-chat-sdk/build/features/messages/threads#pin-thread-message-to-parent-channel).

### Method signature

* Message->Pin() 1Message->Pin();
* Channel->PinMessage() 1Channel->PinMessage(UPubnubChatMessage* Message);

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

#### Output

| Method | Return type | Description |
| --- | --- | --- |
| `Message->Pin()` | `FPubnubChatOperationResult` | Result of the operation. Check `Error` and `ErrorMessage` for failure. |
| `Channel->PinMessage()` | `FPubnubChatOperationResult` | Result of the operation. Check `Error` and `ErrorMessage` for failure. |

### Sample code

:::tip Reference code
This example is a self-contained code snippet ready to be run. Set up your Unreal project and follow the instructions in the lines marked with `ACTION REQUIRED` before running the code. Use it as a reference when working with other examples in this document.
:::

Pin a message to its channel asynchronously.

###### C++

###### Actor.h

```cpp
// blueprint.csuliofh
UFUNCTION(BlueprintCallable, Category = "PubnubChat|Samples|ChatMessage")
void PinMessageSample();
```

###### Actor.cpp

```cpp
// ACTION REQUIRED: Replace ASample_ChatMessage with name of your Actor class
void ASample_ChatMessage::PinMessageSample()
{
	// snippet.hide
	UPubnubChatMessage* Message = nullptr;
	// snippet.show

	// Assumes Message is a valid UPubnubChatMessage

	// Pin this message to its channel
	Message->PinAsync(nullptr);
}
```

###### Blueprint

* `PinMessage()` (on `Channel`)

```cpp
// ACTION REQUIRED: Replace ASample_ChatChannel with name of your Actor class
void ASample_ChatChannel::PinMessageSample()
{
	// snippet.hide
	UPubnubChatChannel* Channel = nullptr;
	// snippet.show

	// Assumes Channel is a valid UPubnubChatChannel (e.g. from GetChannel)

	// Message to pin; must be from this channel or from a thread on this channel
	UPubnubChatMessage* Message = nullptr;

	// Pin a message to this channel (stores in channel metadata)
	Channel->PinMessageAsync(Message, nullptr);
}
```

### Other examples

#### Pin message to channel from Chat object

###### Actor.h

```cpp
UFUNCTION(BlueprintCallable, Category = "PubnubChat|Samples|Chat|Channel")
void PinMessageToChannelSample();

UFUNCTION()
void OnPinMessageToChannelResponse(const FPubnubChatOperationResult& Result);
```

###### Actor.cpp

```cpp
// ACTION REQUIRED: Replace ASample_Chat with name of your Actor class
void ASample_Chat::PinMessageToChannelSample()
{
	// snippet.hide
	UPubnubChat* Chat = nullptr;
	// snippet.show

	// Assumes Chat is a valid and initialized instance of UPubnubChat
	
	// Message: the message to pin (e.g. received from channel listeners or from history)
	UPubnubChatMessage* Message = nullptr;
	// Channel: the channel to pin the message to (e.g. from GetChannel or channel list)
	UPubnubChatChannel* Channel = nullptr;

	FOnPubnubChatOperationResponseNative Callback;
	// ACTION REQUIRED: Replace ASample_Chat with name of your Actor class
	Callback.BindUObject(this, &ASample_Chat::OnPinMessageToChannelResponse);
	Chat->PinMessageToChannelAsync(Message, Channel, Callback);
}

// ACTION REQUIRED: Replace ASample_Chat with name of your Actor class
void ASample_Chat::OnPinMessageToChannelResponse(const FPubnubChatOperationResult& Result)
{
	if (Result.Error) { return; }
	// Pin completed
}
```

## Get

`GetPinnedMessage()` retrieves the currently pinned message.

### Method signature

```cpp
Channel->GetPinnedMessage();
```

#### Output

| Field | Type | Description |
| --- | --- | --- |
| `Result` | `FPubnubChatOperationResult` | Operation result with `Error` and `ErrorMessage`. |
| `Message` | `UPubnubChatMessage*` | The pinned [Message object](https://www.pubnub.com/docs/chat/unreal-chat-sdk/learn/chat-entities/message), or null if no message is currently pinned to the channel. |

### Sample code

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

```cpp
// ACTION REQUIRED: Replace ASample_ChatChannel with name of your Actor class
void ASample_ChatChannel::GetPinnedMessageSample()
{
	// snippet.hide
	UPubnubChatChannel* Channel = nullptr;
	// snippet.show

	// Assumes Channel is a valid UPubnubChatChannel (e.g. from GetChannel)

	// Callback for when the operation completes (returns pinned message or empty)
	FOnPubnubChatMessageResponseNative Callback;
	// ACTION REQUIRED: Replace ASample_ChatChannel with name of your Actor class
	Callback.BindUObject(this, &ASample_ChatChannel::OnGetPinnedMessageResponse);
	Channel->GetPinnedMessageAsync(Callback);
}

// ACTION REQUIRED: Replace ASample_ChatChannel with name of your Actor class
void ASample_ChatChannel::OnGetPinnedMessageResponse(const FPubnubChatMessageResult& Result)
{
	if (Result.Result.Error) { return; }
	UPubnubChatMessage* PinnedMessage = Result.Message;
}
```

## Unpin from message

`Unpin()` called on a message object unpins it from the channel.

### Method signature

```cpp
Message->Unpin();
```

#### Output

| Type | Description |
| --- | --- |
| `FPubnubChatOperationResult` | Result of the operation. Check `Error` and `ErrorMessage` for failure. |

### Sample code

Unpin a message.

#### C++

```cpp
// ACTION REQUIRED: Replace ASample_ChatMessage with name of your Actor class
void ASample_ChatMessage::UnpinMessageSample()
{
	// snippet.hide
	UPubnubChatMessage* Message = nullptr;
	// snippet.show

	// Assumes Message is a valid UPubnubChatMessage

	// Unpin this message from its channel
	Message->UnpinAsync(nullptr);
}
```

#### Blueprint

## Unpin from channel

`UnpinMessage()` called on a channel object unpins the currently pinned message from the channel.

Alternatively, unpin thread messages from the [parent channel](https://www.pubnub.com/docs/chat/unreal-chat-sdk/build/features/messages/threads#unpin-thread-message-from-parent-channel).

### Method signature

```cpp
Channel->UnpinMessage();
```

#### Output

| Type | Description |
| --- | --- |
| `FPubnubChatOperationResult` | Result of the operation. Check `Error` and `ErrorMessage` for failure. |

### Sample code

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

```cpp
// ACTION REQUIRED: Replace ASample_ChatChannel with name of your Actor class
void ASample_ChatChannel::UnpinMessageSample()
{
	// snippet.hide
	UPubnubChatChannel* Channel = nullptr;
	// snippet.show

	// Assumes Channel is a valid UPubnubChatChannel (e.g. from GetChannel)

	// Remove the currently pinned message from this channel
	Channel->UnpinMessageAsync(nullptr);
}
```

### Other examples

#### Unpin message from channel from Chat object

###### Actor.h

```cpp
UFUNCTION(BlueprintCallable, Category = "PubnubChat|Samples|Chat|Channel")
void UnpinMessageFromChannelSample();

UFUNCTION()
void OnUnpinMessageFromChannelResponse(const FPubnubChatOperationResult& Result);
```

###### Actor.cpp

```cpp
// ACTION REQUIRED: Replace ASample_Chat with name of your Actor class
void ASample_Chat::UnpinMessageFromChannelSample()
{
	// snippet.hide
	UPubnubChat* Chat = nullptr;
	// snippet.show

	// Assumes Chat is a valid and initialized instance of UPubnubChat
	
	// Channel: the channel to unpin the current pinned message from (e.g. from GetChannel or channel list)
	UPubnubChatChannel* Channel = nullptr;

	FOnPubnubChatOperationResponseNative Callback;
	// ACTION REQUIRED: Replace ASample_Chat with name of your Actor class
	Callback.BindUObject(this, &ASample_Chat::OnUnpinMessageFromChannelResponse);
	Chat->UnpinMessageFromChannelAsync(Channel, Callback);
}

// ACTION REQUIRED: Replace ASample_Chat with name of your Actor class
void ASample_Chat::OnUnpinMessageFromChannelResponse(const FPubnubChatOperationResult& Result)
{
	if (Result.Error) { return; }
	// Unpin completed
}
```