---
source_url: https://www.pubnub.com/docs/chat/unreal-chat-sdk/build/features/users/create
title: Create users
updated_at: 2026-05-19T12:10:34.543Z
---

> 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


# Create users

Use `CreateUser()` to create a new [User](https://www.pubnub.com/docs/chat/unreal-chat-sdk/learn/chat-entities/user) with a unique [User ID](https://www.pubnub.com/docs/general/basics/identify-users-and-devices).

:::note Requires App Context
Enable [App Context](https://youtu.be/9UEoSlngpYI) on your keyset in the [Admin Portal](https://admin.pubnub.com/) to store user data.
:::

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

#### C++ / Input parameters

```cpp
Chat->CreateUser(
    FString UserID, 
    FPubnubChatUserData UserData
);
```

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| UserID | FString | Yes |  | [Unique user identifier](https://www.pubnub.com/docs/general/setup/users-and-devices#user-id-usage). |
| UserData | FPubnubChatUserData | Optional |  | Additional user data. |

#### FPubnubChatUserData

| Parameter | Description |
| --- | --- |
| `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](https://www.pubnub.com/docs/general/metadata/filtering) 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`. |

#### Blueprint

:::tip API limits
To learn about the maximum length of parameters used to set user metadata, refer to [REST API docs](https://www.pubnub.com/docs/sdks/rest-api/set-user-metadata).
:::

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

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

###### C++

###### Actor.h

```cpp
// blueprint.b-bl8bam
UFUNCTION(BlueprintCallable, Category = "PubnubChat|Samples|Chat|User")
void CreateUserSample();
	
UFUNCTION()
void OnCreateUserResponse(const FPubnubChatUserResult& Result);
```

###### Actor.cpp

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

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

	// Prepare initial metadata for a new user (e.g. when registering a new player profile)
	FPubnubChatUserData UserData;
	UserData.UserName = TEXT("WinningPlayer");
	UserData.ProfileUrl = TEXT("https://example.com/avatars/player.png");

	// Bind a callback with signature matching FOnPubnubChatUserResponseNative, then call Async
	FOnPubnubChatUserResponseNative Callback;
	// ACTION REQUIRED: Replace ASample_Chat with name of your Actor class
	Callback.BindUObject(this, &ASample_Chat::OnCreateUserResponse);
	Chat->CreateUserAsync(TEXT("Player_002"), Callback, UserData);
}

// ACTION REQUIRED: Replace ASample_Chat with name of your Actor class
void ASample_Chat::OnCreateUserResponse(const FPubnubChatUserResult& Result)
{
	if (Result.Result.Error) { return; }
	UPubnubChatUser* NewUser = Result.User;
	// Use NewUser; if user already exists, Result.Result.Error will be set and you may call GetUser instead
}
```

###### Blueprint