Manage user details

Retrieve user details from your app.

icon

Usage in Blueprints and C++


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.

    1Chat->GetUserAsync(UserID, OnGetUserResponseDelegate);

    You can also use native callbacks that accept lambdas instead of dynamic delegates. Native callback types have the Native suffix (for example, FOnPubnubChatUserResponseNative).

  • Synchronous methods (no suffix) block the main game thread until the operation completes and return a result struct directly.

    1FPubnubChatUserResult Result = Chat->GetUser(UserID);

Get user details​

GetUser() returns data about a specific user, including all custom metadata by default.

Requires App Context

Enable App Context in the Admin Portal to store user data.

Method signature​

1Chat->GetUser(FString UserID)
required
UserID required#
Type: FString

Output​

TypeDescription
FPubnubChatUserResultReturned object containing Result (FPubnubChatOperationResult) and User (UPubnubChatUser*). The user is nullptr if not found.

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.

Fetch a user by ID asynchronously.

Actor.h​
1UFUNCTION(BlueprintCallable, Category = "PubnubChat|Samples|Chat|User")
2void GetUserSample();
3
4UFUNCTION()
5void OnGetUserResponse(const FPubnubChatUserResult& Result);
Actor.cpp​
1

2#include "PubnubChatUser.h"
3
4// ACTION REQUIRED: Replace ASample_Chat with name of your Actor class
5void ASample_Chat::GetUserSample()
6{
7
8 // Assumes Chat is a valid and initialized instance of UPubnubChat
9
10 // Bind a callback with signature matching FOnPubnubChatUserResponseNative, then call Async
11 FOnPubnubChatUserResponseNative Callback;
12 // ACTION REQUIRED: Replace ASample_Chat with name of your Actor class
13 Callback.BindUObject(this, &ASample_Chat::OnGetUserResponse);
14 Chat->GetUserAsync(TEXT("Player_002"), Callback);
15}
show all 23 lines

Get current user​

GetCurrentUser() returns the current chat user.

Requires App Context

Enable App Context in the Admin Portal to store user data.

Method signature​

1Chat->GetCurrentUser();

Output​

TypeDescription
UPubnubChatUser*Returned User object.

Sample code​

Return the current chat user.

1

2#include "PubnubChatUser.h"
3
4// ACTION REQUIRED: Replace ASample_Chat with name of your Actor class
5void ASample_Chat::GetCurrentUserSample()
6{
7
8 // Assumes Chat is a valid and initialized instance of UPubnubChat
9
10 // Get the current chat user (local, no network call — the player who owns this chat session)
11 UPubnubChatUser* CurrentUser = Chat->GetCurrentUser();
12 if (CurrentUser)
13 {
14 // Use CurrentUser for display name, avatar URL, or to fetch memberships
15 FString DisplayName = CurrentUser->GetUserData().UserName;
show all 17 lines

Get user ID​

GetUserID() returns the current chat user's ID.

Method signature​

1User->GetUserID();

Output​

TypeDescription
FStringReturned user ID.

Sample code​

Return the current chat user's ID.

1

2// ACTION REQUIRED: Replace ASample_ChatUser with name of your Actor class
3void ASample_ChatUser::GetUserIDSample()
4{
5
6 // Assumes User is a valid UPubnubChatUser (e.g. from GetUser)
7
8 // Get the user ID (local, no network call)
9 FString UserID = User->GetUserID();
10}

Get user data​

GetUserData() returns the current chat user's data.

Method signature​

1User->GetUserData();

Output​

TypeDescription
FPubnubChatUserDataReturned user data from the local cache.

Sample code​

Return the current chat user's data.

1

2// ACTION REQUIRED: Replace ASample_ChatUser with name of your Actor class
3void ASample_ChatUser::GetUserDataSample()
4{
5
6 // Assumes User is a valid UPubnubChatUser (e.g. from GetUser)
7
8 // Get user metadata from local cache (local, no network call)
9 FPubnubChatUserData UserData = User->GetUserData();
10 FString UserName = UserData.UserName;
11}

Was this page useful?

Last updated on