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.
Asynchronous and synchronous method execution
Most PubNub Unreal SDK methods are available in both asynchronous and synchronous variants.
-
Asynchronous methods (
Asyncsuffix) returnvoidand 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
Nativesuffix (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
- C++ / Input parameters
- Blueprint
1Chat->CreateUser(
2 FString UserID,
3 FPubnubChatUserData UserData
4);
| Parameter | Description |
|---|---|
UserID *Type: FString | Unique user identifier. |
UserDataType: FPubnubChatUserData | Additional user data. |
FPubnubChatUserData
| Parameter | Description |
|---|---|
UserNameType: FStringDefault: n/a | Display name for the user (must not be empty or consist only of whitespace characters). |
ExternalIDType: FStringDefault: n/a | User's identifier in an external system. You can use it to match id with a similar identifier from an external database. |
ProfileUrlType: FStringDefault: n/a | URL of the user's profile picture. |
EmailType: FStringDefault: n/a | User's email address. |
CustomType: FStringDefault: 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. |
StatusType: FStringDefault: 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. |
TypeType: FStringDefault: 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
| Type | Description |
|---|---|
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.