---
source_url: https://www.pubnub.com/docs/chat/unreal-chat-sdk/build/features/users/mentions
title: Mention users
updated_at: 2026-06-12T11:23:24.952Z
---

> 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


# Mention users

Tag users in chat messages with `@` mentions. Type `@` followed by at least three letters to see username 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) in the [Admin Portal](https://admin.pubnub.com/) to mention users.
:::

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

**Configuration options:**

* **User source**: channel members or all app users
* **Suggestions**: up to 100 usernames (default: 10)
* **Username length**: up to [200 characters](https://www.pubnub.com/docs/sdks/javascript/api-reference/objects#set-user-metadata)
* **Mentions per message**: up to 100 (default: 10)

Implementation follows similar patterns to [channel referencing](https://www.pubnub.com/docs/chat/unreal-chat-sdk/build/features/channels/references) and [links](https://www.pubnub.com/docs/chat/unreal-chat-sdk/build/features/messages/links).

## Add user mentions

`AddMention()` adds user mentions to a [draft message](https://www.pubnub.com/docs/chat/unreal-chat-sdk/build/features/messages/drafts). Use `CreateUserMentionTarget()` to create a mention target linking to a specified `User`.

### Method signature

Add a user mention by calling `AddMention()` with the `MentionTarget` of type `User`.

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 `Alex` is a user mention.

###### Actor.h

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

###### Actor.cpp

```cpp
// ACTION REQUIRED: Replace ASample_ChatMessageDraft with name of your Actor class
void ASample_ChatMessageDraft::AddUserMentionSample()
{
	// 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 UserName = "Alex";
	FPubnubChatMentionTarget UserMentionTarget = UPubnubChatMessageDraftUtilities::CreateUserMentionTarget(UserName);

	MyMessageDraft->AddMention(6, UserName.Len(), UserMentionTarget);

	MyMessageDraft->Send();
}
```

## Remove user mentions

`RemoveMention()` removes a user mention from a [draft message](https://www.pubnub.com/docs/chat/unreal-chat-sdk/build/features/messages/drafts).

### Method signature

Remove a user mention by calling `RemoveMention()` at the exact offset where the mention 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 offset position where the mention starts; otherwise, it won't be 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 user mention from the `Hello Alex! I have sent you this link on the #offtopic channel.` message where `Alex` is a user mention.

###### 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 user suggestions

The `OnMessageDraftUpdatedWithSuggestions` delegate returns users matching a 3-letter string from channel members or global users. Bind this delegate to receive draft changes along with suggestions for user mentions, links, and channel references.

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

Example: typing `@Ale` returns users starting with `Ale` like `Alex` or `Alexander`. 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 mentioned user whenever the draft is updated and users 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 user suggestions from Chat object

###### Actor.h

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

UFUNCTION()
void OnGetUserSuggestionsResponse(const FPubnubChatGetUserSuggestionsResult& Result);
```

###### Actor.cpp

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

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

	// Bind a callback with signature matching FOnPubnubChatGetUserSuggestionsResponseNative, then call Async
	FOnPubnubChatGetUserSuggestionsResponseNative Callback;
	// ACTION REQUIRED: Replace ASample_Chat with name of your Actor class
	Callback.BindUObject(this, &ASample_Chat::OnGetUserSuggestionsResponse);
	Chat->GetUserSuggestionsAsync(TEXT("Win"), Callback, 10);
}

// ACTION REQUIRED: Replace ASample_Chat with name of your Actor class
void ASample_Chat::OnGetUserSuggestionsResponse(const FPubnubChatGetUserSuggestionsResult& Result)
{
	if (Result.Result.Error) { return; }
	for (UPubnubChatUser* User : Result.Users)
	{
		/* add to suggestion list in UI */
	}
}
```

## Get mentioned users

:::warning Removed method
`MentionedUsers()` has been removed from the `Message` object in the latest version of the Unreal Chat SDK. Mentioned users are now managed through [MessageDraft](https://www.pubnub.com/docs/chat/unreal-chat-sdk/learn/chat-entities/message-draft) and message elements. To monitor mentions, use the `OnMentioned` delegate on the `User` object or [StreamMentions()](#show-notifications-for-mentions).
:::

## Collect all user-related mentions

:::warning Removed method
`GetCurrentUserMentions()` has been removed from the `Chat` object in the latest version of the Unreal Chat SDK. To monitor mentions, use the `OnMentioned` delegate or [StreamMentions()](#show-notifications-for-mentions), or [GetEventsHistory()](https://www.pubnub.com/docs/chat/unreal-chat-sdk/build/features/custom-events#get-historical-events) to retrieve historical mention events.
:::

## Show notifications for mentions

Use the `OnMentioned` delegate on the `User` object to receive real-time mention events. Bind the delegate and call `StreamMentions()` to start receiving mention events targeted to the user. Call `StopStreamingMentions()` to stop.

| Delegate | Type | Payload |
| --- | --- | --- |
| `OnMentioned` | `FOnPubnubChatUserMentioned` | `FPubnubChatUserMention` containing mention details (channel ID, message timetoken, etc.). |

### Sample code

###### Actor.h

```cpp
UFUNCTION(BlueprintCallable, Category = "PubnubChat|Samples|ChatUser")
void StreamMentionsSample();

void OnUserMentioned(const FPubnubChatUserMention& UserMention);
```

###### Actor.cpp

```cpp
// ACTION REQUIRED: Replace ASample_ChatUser with name of your Actor class
void ASample_ChatUser::StreamMentionsSample()
{
	// snippet.hide
	UPubnubChatUser* User = nullptr;
	// snippet.show

	// Assumes User is a valid UPubnubChatUser (e.g. from GetCurrentUser)

	// Bind to receive mention notifications for this user
	User->OnMentionedNative.AddUObject(this, &ASample_ChatUser::OnUserMentioned);

	// Start streaming mentions
	User->StreamMentionsAsync(nullptr);

	// When mention notifications are no longer needed, stop streaming
	User->StopStreamingMentionsAsync(nullptr);
}

// ACTION REQUIRED: Replace ASample_ChatUser with name of your Actor class
void ASample_ChatUser::OnUserMentioned(const FPubnubChatUserMention& UserMention)
{
	/* e.g. show @mention notification in UI */
}
```

## Emit user mention

Programmatically emit a mention event on a channel with `EmitUserMention()`. Use this when implementing custom mention logic outside of [MessageDraft](https://www.pubnub.com/docs/chat/unreal-chat-sdk/build/features/messages/drafts), for example when processing messages that arrive from external systems.

### Method signature

#### C++ / Input parameters

```cpp
Channel->EmitUserMention(
    const FString UserID,
    const FString Timetoken,
    const FString Text
);
```

| Parameter | Description |
| --- | --- |
| `UserID` *Type: `FString`Default: n/a | ID of the user being mentioned. |
| `Timetoken` *Type: `FString`Default: n/a | Timetoken of the message that contains the mention. |
| `Text` *Type: `FString`Default: n/a | Content of the message containing the mention. |

#### Blueprint

#### Output

| Type | Description |
| --- | --- |
| `FPubnubChatOperationResult` | Contains `Error` and `ErrorMessage`. Check `Error` to determine if the event was emitted successfully. |

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

Emit a mention event for a user on a channel.

###### Actor.h

```cpp
UFUNCTION(BlueprintCallable, Category = "PubnubChat|Samples|ChatChannel")
void EmitUserMentionSample();
```

###### Actor.cpp

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

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

	// User ID being mentioned
	FString UserID = TEXT("user-abc123");
	// Timetoken of the message that contains the mention (17-digit PubNub timetoken)
	FString Timetoken = TEXT("17388000000000000");
	// Mention text to display (e.g. @username)
	FString Text = TEXT("@johndoe");

	// Emit a mention event for @mention notifications
	Channel->EmitUserMentionAsync(UserID, Timetoken, Text, nullptr);
}
```