On this page

Mention users

Tag users in chat messages with @ mentions. Type @ followed by at least three letters to see username suggestions.

icon

Usage in Blueprints and C++


Requires App Context

Enable App Context in the Admin Portal to mention users.

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
  • Mentions per message: up to 100 (default: 10)

Implementation follows similar patterns to channel referencing and links.

Add user mentions​

AddMention() adds user mentions to a draft message. 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() method for details.

Sample code​

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​
1

Actor.cpp​
1

Remove user mentions​

RemoveMention() removes a user mention from a draft message.

Method signature​

Remove a user mention by calling RemoveMention() at the exact offset where the mention starts.

Refer to the RemoveMention() method for details.

Offset value

Provide the exact offset position where the mention starts; otherwise, it won't be removed.

Sample code​

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​
1

Actor.cpp​
1

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.

icon

Details


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) section for details.

Sample code​

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​
1

Actor.cpp​
1

Other examples​

Get user suggestions from Chat object​

Actor.h​
1

Actor.cpp​
1

Get mentioned users​

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 and message elements. To monitor mentions, use the OnMentioned delegate on the User object or StreamMentions().

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(), or GetEventsHistory() 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.

DelegateTypePayload
OnMentioned
FOnPubnubChatUserMentioned
FPubnubChatUserMention containing mention details (channel ID, message timetoken, etc.).

Sample code​

Actor.h​
1

Actor.cpp​
1

Emit user mention​

Programmatically emit a mention event on a channel with EmitUserMention(). Use this when implementing custom mention logic outside of MessageDraft, for example when processing messages that arrive from external systems.

Method signature​

1Channel->EmitUserMention(
2 const FString UserID,
3 const FString Timetoken,
4 const FString Text
5);
* required
ParameterDescription
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.

Output​

TypeDescription
FPubnubChatOperationResult
Contains Error and ErrorMessage. Check Error to determine if the event was emitted successfully.

Sample code​

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​
1

Actor.cpp​
1