---
source_url: https://www.pubnub.com/docs/chat/unreal-chat-sdk/build/features/channels/references
title: Reference channels
updated_at: 2026-05-25T11:25:56.345Z
---

> 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


# Reference channels

Channel referencing lets users mention channels in messages by typing `#` followed by at least three letters. Matching channel names appear as suggestions.

##### 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 Requires App Context
Enable [App Context](https://youtu.be/9UEoSlngpYI) for your keyset in the [Admin Portal](https://admin.pubnub.com/).
:::

:::tip Generic referencing
Channel references, user mentions, and links are `MessageElement` instances with different `MentionTarget` types.
:::

Suggestions include all channels in the app keyset (up to 100), regardless of user membership. Configure up to 100 channel references per message (default: 10) and display them as links.

Implementation is similar to [user mentions](https://www.pubnub.com/docs/chat/unreal-chat-sdk/build/features/users/mentions) and [links](https://www.pubnub.com/docs/chat/unreal-chat-sdk/build/features/messages/links).

## Add channel references

Add channel references with `#` followed by at least three letters of the channel name (e.g., `#Sup`). Use `CreateChannelMentionTarget()` to create a mention target linking to a specified `Channel`.

### Method signature

Add a channel reference by calling `AddMention()` with the `MentionTarget` of type `Channel`.

Refer to the [AddMention()](https://www.pubnub.com/docs/chat/unreal-chat-sdk/build/features/messages/drafts#add-message-element) method for details.

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

Create the `Hello Alex! I have sent you this link on the #offtopic channel.` message where `#offtopic` is a channel reference (channel name is `offtopic`).

###### Actor.h

```cpp
UFUNCTION(BlueprintCallable, Category = "PubnubChat|Samples|ChatMessageDraft")
void AddChannelReferenceSample();
```

###### Actor.cpp

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

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

	UPubnubChatMessageDraft* MyMessageDraft = Channel->CreateMessageDraft();

	MyMessageDraft->InsertText(0, "Hello Alex! I have sent you this link on the #offtopic channel.");

	FString ChannelName = "offtopic";
	FPubnubChatMentionTarget ChannelMentionTarget = UPubnubChatMessageDraftUtilities::CreateChannelMentionTarget(ChannelName);

	MyMessageDraft->AddMention(45, ChannelName.Len() + 1, ChannelMentionTarget);

	MyMessageDraft->Send();
}
```

## Remove channel references

Remove a channel reference from a [draft message](https://www.pubnub.com/docs/chat/unreal-chat-sdk/build/features/messages/drafts) with `RemoveMention()`.

### Method signature

Remove channel references by calling `RemoveMention()` at the exact offset where the reference starts.

Refer to the [RemoveMention()](https://www.pubnub.com/docs/chat/unreal-chat-sdk/build/features/messages/drafts#remove-message-element) method for details.

:::warning Offset value
Provide the exact position of the first character; otherwise the element is not removed.
:::

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

Remove the channel reference from the `Hello Alex! I have sent you this link on the #offtopic channel.` message where `#offtopic` is a channel reference.

###### Actor.h

```cpp
UFUNCTION(BlueprintCallable, Category = "PubnubChat|Samples|ChatMessageDraft")
void MessageDraftRemoveMentionSample();
```

###### Actor.cpp

```cpp
// ACTION REQUIRED: Replace ASample_ChatMessageDraft with name of your Actor class
void ASample_ChatMessageDraft::MessageDraftRemoveMentionSample()
{
	// snippet.hide
	UPubnubChatMessageDraft* MessageDraft = nullptr;
	// snippet.show

	// Assumes MessageDraft is a valid UPubnubChatMessageDraft with existing mentions
	// e.g. the message reads: "Hello Alex! I have sent you this link on the #offtopic channel."

	// Remove the link mention at position 33
	MessageDraft->RemoveMention(33);
}
```

## Get channel suggestions

The message elements listener returns matching channels from your keyset for the 3-letter string typed after `#`.

##### Details

`OnMessageDraftUpdatedWithSuggestions` delegate:

* Fires when the draft content changes
* Provides the current state of message elements (`TArray<FPubnubChatMessageElement>`)
* Offers `FPubnubChatSuggestedMention` items suggesting user mentions, links, or channel references

Unlike `OnMessageDraftUpdated`, which only delivers content changes, this delegate also includes suggestion data for dynamic draft updates.

Typing `#Sup` returns channels like `Support` or `Support-Agents`. Default: 10 suggestions (max: 100).

### Method signature

Refer to the [Listen for message draft changes (with suggestions)](https://www.pubnub.com/docs/chat/unreal-chat-sdk/build/features/messages/drafts#listen-for-message-draft-changes-with-suggestions) section for details.

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

Insert the first referenced channel whenever the draft is updated and channels are detected.

###### Actor.h

```cpp
UFUNCTION(BlueprintCallable, Category = "PubnubChat|Samples|ChatMessageDraft")
void MessageDraftInsertSuggestedMentionSample();

void OnMessageDraftUpdateWithSuggestions_InsertSample(const TArray<FPubnubChatMessageElement>& MessageElements, const TArray<FPubnubChatSuggestedMention>& SuggestedMentions);
```

###### Actor.cpp

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

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

	UPubnubChatMessageDraft* MyMessageDraft = Channel->CreateMessageDraft();

	// Bind to receive suggestions and automatically insert the first one
	MyMessageDraft->OnMessageDraftUpdatedWithSuggestionsNative.AddUObject(this, &ASample_ChatMessageDraft::OnMessageDraftUpdateWithSuggestions_InsertSample);

	// Trigger the delegate and suggestions
	MyMessageDraft->Update("Please coordinate with @Al for the meeting.");
}

// ACTION REQUIRED: Replace ASample_ChatMessageDraft with name of your Actor class
void ASample_ChatMessageDraft::OnMessageDraftUpdateWithSuggestions_InsertSample(const TArray<FPubnubChatMessageElement>& MessageElements, const TArray<FPubnubChatSuggestedMention>& SuggestedMentions)
{
	// snippet.hide
	UPubnubChatMessageDraft* MyMessageDraft = nullptr;
	// snippet.show

	if (SuggestedMentions.Num() > 0)
	{
		const FPubnubChatSuggestedMention& FirstSuggestion = SuggestedMentions[0];
		MyMessageDraft->InsertSuggestedMention(FirstSuggestion);
		UE_LOG(LogTemp, Log, TEXT("Inserted suggested mention: %s"), *FirstSuggestion.ReplaceTo);
	}
}
```

### Other examples

#### Get channel suggestions from Chat object

###### Actor.h

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

UFUNCTION()
void OnGetChannelSuggestionsResponse(const FPubnubChatGetChannelSuggestionsResult& Result);
```

###### Actor.cpp

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

	// Assumes Chat is a valid and initialized instance of UPubnubChat

	// Get channels whose name starts with the typed text asynchronously (e.g. for channel search autocomplete)
	FOnPubnubChatGetChannelSuggestionsResponseNative Callback;
	// ACTION REQUIRED: Replace ASample_Chat with name of your Actor class
	Callback.BindUObject(this, &ASample_Chat::OnGetChannelSuggestionsResponse);
	Chat->GetChannelSuggestionsAsync(TEXT("Lob"), Callback, 10);
}

// ACTION REQUIRED: Replace ASample_Chat with name of your Actor class
void ASample_Chat::OnGetChannelSuggestionsResponse(const FPubnubChatGetChannelSuggestionsResult& Result)
{
	if (Result.Result.Error) { return; }
	for (UPubnubChatChannel* Channel : Result.Channels)
	{
		/* add to suggestion list in UI */
	}
}
```

## Get referenced channels

:::warning Removed method
`ReferencedChannels()` has been removed from the `Message` object in the latest version of the Unreal Chat SDK. Referenced channels are now managed through [MessageDraft](https://www.pubnub.com/docs/chat/unreal-chat-sdk/learn/chat-entities/message-draft) and message elements.
:::