---
source_url: https://www.pubnub.com/docs/chat/unity-chat-sdk/build/features/users/create
title: Create users
updated_at: 2026-05-25T11:25:52.597Z
---

> 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/unity-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.
:::

### Method signature

This method takes the following parameters:

```csharp
chat.CreateUser(
    string userId, 
    ChatUserData? additionalData = null
)

public class ChatUserData
{
    public string Username { get; set; } = string.Empty;
    public string ExternalId { get; set; } = string.Empty;
    public string ProfileUrl { get; set; } = string.Empty;
    public string Email { get; set; } = string.Empty;
    public Dictionary<string, object> CustomData { get; set; } = new ();
    public string Status { get; set; } = string.Empty;
    public string Type { get; set; } = string.Empty;
}
```

#### Input

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| userId | string | Yes |  | [Unique user identifier](https://www.pubnub.com/docs/general/setup/users-and-devices#user-id-usage). |
| Username | string | Optional | `string.Empty` | Display name for the user (must not be empty or consist only of whitespace characters). |
| ExternalId | string | Optional | `string.Empty` | User's identifier in an external system. You can use it to match `id` with a similar identifier from an external database. |
| ProfileUrl | string | Optional | `string.Empty` | URL of the user's profile picture. |
| Email | string | Optional | `string.Empty` | User's email address. |
| CustomData | Dictionary<string, | Optional | `new ()` | 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 `CustomData` property is not recommended in SDKs. |
| Status | string | Optional | `string.Empty` | 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 | string | Optional | `string.Empty` | 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`. |

:::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 |
| --- | --- |
| `Task<ChatOperationResult<User>>` | An awaitable `Task` with the returned object containing the new [user](https://www.pubnub.com/docs/chat/unity-chat-sdk/learn/chat-entities/user) data. |

### Sample code

Create a user with an ID of `support_agent_15`. Specify their name, avatar, and custom attributes, such as their title and the LinkedIn profile URL.

```csharp
using System.Collections.Generic;
using System.Threading.Tasks;
using PubnubApi;
using PubnubChatApi;

// Configuration
PubnubChatConfig chatConfig = new PubnubChatConfig();
        
PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId"))
{
    SubscribeKey = "demo",
    PublishKey = "demo",
    Secure = true
};

// Initialize Unity Chat
var chatResult = await UnityChat.CreateInstance(chatConfig, pnConfiguration);
if (!chatResult.Error)
{
    chat = chatResult.Result;
}
// Define the custom data for the user
var userData = new ChatUserData
{
    Username = "Support Agent",
    ProfileUrl = "https://example.com/avatar.png",
    Email = "agent@example.com",
    CustomData = new Dictionary<string, object>
    {
        { "title", "Customer Support Agent" },
        { "linkedin_profile", "https://www.linkedin.com/in/support-agent" }
    },
    Status = "active",
    Type = "support"
};

// Create the user with the specified ID and custom data
var result = await chat.CreateUser("support_agent_15", userData);
var user = result.Result;
```