On this page

Create users

Use CreateUser() to create a new User with a unique User ID.

Requires App Context

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

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->CreateUserAsync(UserID, UserData, OnCreateUserResponseDelegate);

    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->CreateUser(UserID, UserData);

Method signature

1Chat->CreateUser(
2 FString UserID,
3 FPubnubChatUserData UserData
4);
* required
ParameterDescription
UserID *
Type: FString
Unique user identifier.
UserDataAdditional user data.

FPubnubChatUserData


* required
ParameterDescription
UserName
Type: FString
Default:
n/a
Display name for the user (must not be empty or consist only of whitespace characters).
ExternalID
Type: FString
Default:
n/a
User's identifier in an external system. You can use it to match id with a similar identifier from an external database.
ProfileUrl
Type: FString
Default:
n/a
URL of the user's profile picture.
Email
Type: FString
Default:
n/a
User's email address.
Custom
Type: FString
Default:
n/a
JSON providing custom data about the user. Values must be scalar only; arrays or objects are not supported. Filtering App Context data through the custom property is not recommended in SDKs.
Status
Type: FString
Default:
n/a
Tag that lets you categorize your app users by their current state. The tag choice is entirely up to you and depends on your use case. For example, you can use status to mark users in your chat app as invited, active, or archived.
Type
Type: FString
Default:
n/a
Tag that lets you categorize your app users by their functional roles. The tag choice is entirely up to you and depends on your use case. For example, you can use type to group users by their roles in your app, such as moderator, player, or support-agent.
API limits

To learn about the maximum length of parameters used to set user metadata, refer to REST API docs.

Output

TypeDescription
FPubnubChatUserResult
Returned object containing Result (FPubnubChatOperationResult) and User (UPubnubChatUser*).

Errors

If you try to create a user without providing their ID, you will receive the ID is required error. If you try to create a user that already exists, you will receive the User with this ID already exists error.

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 a new user with metadata asynchronously.

Actor.h
1

Actor.cpp
1

Last updated on