# PubNub Text Chat

{% hint style="danger" %}
Due for Simplification, please speak to support for further info.

**31/01/2025:** MSquared is not maintaining the text chat that uses PubNub and Community Sift. We do provide a simple example of text chat that does not use these features (see [Unreal Text Chat](/creation/unreal-development/features-and-tutorials/communication/unreal-text-chat.md)). If customers wish to continue using these services, they need to speak to the Solutions Engineering team for guidance on how to implement this within their project outside of what MSquared provides off the shelf.

When MSquared drops support for PubNub, we will no longer support Web-to-Unreal text chat. Chat will be limited to Unreal Worlds within MSquared.

This legacy text chat is used in the deprecated UI elements (`WBP_Origin_HUD` still uses the deprecated `WBP_M2_TextChat`, however the M2 Example plugin does not use this, instead using a different `WBP_M2Example_TextChat`, which points to the new Unreal chat component.

Until MSquared completely drops support of PubNub and Community sift, they will remain functional. When the new simplified chat lands, the old chat widget will remain within the platform for customer use.

MSquared will not be addressing non-critical and cosmetic issues relating to Text Chat during this process of simplification. Please reach out to your Support Engineers with concerns.
{% endhint %}

{% hint style="warning" %}
If your project is running on V37 or older, you may have to use alternative settings. Please reach our to your Support Engineer to assist you.
{% endhint %}

{% hint style="info" %}
**Beta Quality** - Customers are encouraged to test and use Beta features in their experiences, but may still require some support
{% endhint %}

### Overview <a href="#in-and-out-experiencechat-overview" id="in-and-out-experiencechat-overview"></a>

The ability to chat on web and in game, including:

* Chat from Web to Unreal and back
* Works on Desktop and Mobile\*
* Text appears in game above the head
* Ability to hide and show the widget, and custom sizing
* User name and profile image appending to the message

The in-and-out-experience chat is backed by [PubNub](https://www.pubnub.com/). For battle-tested, in-experience only chat, see [Experience Only Chat](/creation/unreal-development/features-and-tutorials/communication/text-chat/in-experience-chat/experience-only-chat.md).

{% hint style="danger" %}
\* Mobile is currently only supported via the old chat UI ([Cloud Chat](https://app.gitbook.com/o/N6rN2gq2jZJWtEY3WRk3/s/oWTlPaoHd1McSakqMigu/~/changes/496/tutorials-and-features/communication/in-and-out-experience-chat/in-experience-chat/cloud-chat)). See [Adding Mobile support](#adding-mobile-support) to continue use of this version of the text chat for desktop
{% endhint %}

## Integration <a href="#integration" id="integration"></a>

1. Make sure you have a safe internal world id set up for your editor users.
2. Configure the variable `Social.Chat.Editor.World` in `deployment.json` with this value (see below)

## How to enable <a href="#how-to-enable" id="how-to-enable"></a>

1. Enable `TextChat.UseCloudChat` in `game.json`.
2. Make sure your in-game HUD is set up to use the new chat system

The following settings in `game.json` influence the Text Chat feature:

<table data-header-hidden><thead><tr><th width="290.3333333333333">Setting</th><th width="306">Description</th><th>Default Value</th></tr></thead><tbody><tr><td><strong>Setting</strong></td><td><strong>Description</strong></td><td><strong>Default Value</strong></td></tr><tr><td><code>TextChat.UseCloudChat</code></td><td>Enables the cloud chat functionality</td><td>true</td></tr><tr><td><code>TextChat.ForceMobileView</code></td><td>Forces mobile view regardless of detected platform</td><td>false</td></tr></tbody></table>

## How to enable Text chat in Editor

The steps taken will depend on your sign-in settings. Navigate to `Editor Preferences` > `General` > `Sign in Settings`. If `Use Local World For PIE` is enabled then follow the instructions for using a local world below. By default, this setting should be true.

{% tabs %}
{% tab title="Using local world" %}
If you are using local world sign in then nothing needs to be done. You will automatically be configured a chat channel named after your users unique local world Id.
{% endtab %}

{% tab title="Not using local world" %}
Create a `deployment.override.json` in your project live config directory (Config/LiveConfig/Overrides) and add the following, replacing the `World` value with any unique name for your chat channel.\\

<pre><code><strong>{    
</strong><strong>    "Social": { 
</strong>        "Chat": { 
<strong>            "Editor": { 
</strong>                "WorldSource": "LiveConfig", 
                "World": [REPLACE WITH WORLD ID] 
<strong>            }
</strong>        }
    }
}
</code></pre>

{% endtab %}
{% endtabs %}

## Live Config configuration

The following `deployment.json` live config fields influence the Text Chat feature:

| Setting                                                   | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       | Default Value                             |
| --------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------- |
| `Social.Chat.WorldSource`                                 | <p>Determines how the client should determine the world id to use for chat.<br></p><p>The values are as follows:</p><ul><li><mark style="color:blue;"><code>Domain</code></mark> - Uses the current <code>WorldId</code> value of the Domain Configuration Subsystem. This can change per-player at runtime. Therefore a single users chat channel can change during the game. For example if the player world travels.</li><li><mark style="color:blue;"><code>LiveConfig</code></mark> - Uses the <code>Social.Chat.World</code> value. As a live config value this can be changed for all players by modifying the live config settings via the dashboard.</li><li><mark style="color:blue;"><code>CommandLine</code></mark> - Uses the client cli launch arguments. These are static throughout gameplay for each client and therefore even if you world travel, clients will continue to use the same chat channel</li></ul> | <mark style="color:blue;">`Domain`</mark> |
| `Social.Chat.World`                                       | <p>This is a generic, hard coded chat channel name.</p><p>It is named "World" because the other sources will use the world Id however any unique name could be used as the chat channel</p><p><strong>Only used when <code>Social.Chat.WorldSource</code> is set to <code>LiveConfig.</code></strong></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         | *Empty*                                   |
| `Social.Chat.Editor.WorldSource`                          | <p>Exactly the same as <code>Social.Chat.WorldSource</code> but used when in the Editor. For example in Play-in-Editor (PIE) scenarios.<br><br><strong>The default value will only work if you are signing in with a local world. If you are not using a local world, you should change this value.</strong></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  | <mark style="color:blue;">`Domain`</mark> |
| Social.Chat.Editor.World                                  | <p>Exactly the same as Social.Chat.World but used when in the Editor. For example in Play-in-Editor (PIE) scenarios.<br><br><strong>Only used when <code>Social.Chat.Editor.WorldSource</code> is set to <code>LiveConfig.</code></strong></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    | *Empty*                                   |
| <p>M2.Domains.WorldId</p><p><strong>(LEGACY)</strong></p> | <p>The world id in the web to scope the chat to.</p><p>This must match the web portals if you want cross-experience chat.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |                                           |

## Adding Chat to your HUD

Add `WBP_M2_TextChat` to your HUD and ensure it is stretched across the whole screen.

### Adding Mobile Support

`WBP_M2_TextChat` does not yet support mobile platforms. If your HUD is or derives from `WBP_TH_HUD` then your good to go. Otherwise follow the below steps:

Use a widget switcher to switch between `WBP_M2_TextChat` and `WBP_TextChatWindow_Mobile` with the following code to allow it to automatically revert to the old UI for mobile devices.

1. On Bootflow finished, add a handle to get live config updates.

<figure><img src="/files/k15Nxe6bz8iZJZ7ZG5am" alt=""><figcaption><p>Add a Handle to Config Updated to get Live config event updates</p></figcaption></figure>

2. Create a function called Update Live Config and add the following:

<figure><img src="/files/4PcrpEI5JeEFFG5Db1KB" alt=""><figcaption><p>Create a function which determines which chat UI version to use</p></figcaption></figure>

## Full Live Config Setting List

Settings marked (LEGACY) may be removed in a future update

| Setting                                                             | Description                                                                                                                         | Default Value |
| ------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- | ------------- |
| `TextChat.GlobalChatEnabled`                                        | Enables the Global Chat channel                                                                                                     | true          |
| `TextChat.UseCloudChat`                                             | Enables use of the cloud based chat system, linking the in game chat with web chat                                                  | true          |
| `TextChat.ForceMobileView`                                          | Forces the old Chat UI (`WBP_TextChatWindow_Mobile`) to a full screen mobile view, regardless of platform or device used            | false         |
| `TextChat.ForceMobileUI`                                            | Force the old Chat UI (`WBP_TextChatWindow_Mobile`) to be used over the new `WBP_M2_TextChat` regardless of platform or device used | false         |
| `TextChat.StartMinimized`                                           | Sets the chat interfaces to start in a minimized state                                                                              | true          |
| `TextChat.EmojiMenuEnabled`                                         | Enables the in game emoji menu to be used. Only supported in `WBP_M2_TextChat`                                                      | true          |
| `TextChat.ReactionsEnabled`                                         | Enables message reactions. Still WIP, not yet supported in Origin                                                                   | false         |
| `TextChat.MaxHistoryMessages`                                       | Max messages to be displayed in the chat interface                                                                                  | 100           |
|                                                                     |                                                                                                                                     |               |
| <p><code>TextChat.LocalChatEnabled</code></p><p>(LEGACY)</p>        | Enables Local chat functionality for Experience only chat                                                                           | true          |
| <p><code>TextChat.LocalRateLimitPerSecond</code></p><p>(LEGACY)</p> | Maximum number of messages a player can send per second                                                                             | 10            |
| <p><code>TextChat.LocalRateLimitQueueSize</code></p><p>(LEGACY)</p> | Defines the message queue size for the local chat server                                                                            | 100           |
| <p><code>TextChat.AllowQuestions</code></p><p>(LEGACY)</p>          | Allows questions to be sent in chat                                                                                                 | false         |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.msquared.io/creation/unreal-development/features-and-tutorials/communication/text-chat.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
