# Unreal Text Chat

{% hint style="success" %}
verified: 2025-11-19 version: v39
{% endhint %}

In [Example Plugin](/platform-documentation/creation/unreal-development/features-and-tutorials/the-m2-example-plugin.md), we have a simple example chat system that can be used for small/medium sized experiences. It doesn't use an external web service (e.g. PubNub), instead handling the messaging through the Unreal machines, via Morpheus networking.

<figure><img src="/files/PaA9l4Ac3HX4Iqm1h8H0" alt=""><figcaption></figcaption></figure>

## The main classes

### The singleton (BPM\_M2Example\_TextChatSingleton)

This is the morpheus actor that handles the networking involved in sending these Unreal text chat messages. Clients call `SendChatMessage`, which sends an RPC to the server. The server then reviews the message, and broadcasts it to the clients via a multicast RPC.

<figure><img src="/files/fAKCkG2tDbEPhrj7dpxg" alt=""><figcaption></figcaption></figure>

#### A note on moderation

We add a `ProcessMessage` step at the point of receiving a `Server_SendChatMessage` RPC, which acts as an entry point for adding moderation/chat filtering. The example is just a simple check that rejects messages that are too long, but more complex moderation could be added here, such as rejecting certain words, or interacting with an external service like CommunitySift.

(Note that adding complex logic to this `ProcessMessage` method may slow the server down at scale, since the computation is being run on the server for each message that gets processed in this example)

<figure><img src="/files/Jk356wkY2KRxFWQtmcIu" alt=""><figcaption></figcaption></figure>

#### Rate Limiting

{% hint style="warning" %}
Rate Limiting is entirely optional, but highly recommended. We scale test our content with the settings detailed below and cannot guarantee a performant experience if lower limits are used or this logic is removed.
{% endhint %}

If you look at `BPMC_M2Example_TextChatComponent` you will find an example of how we rate limit on clients. The intent here is to limit the number of messages processed by the server to reduce impact on performance. Rate limiting here scales so that as the user count increases, a delay is added to the message being sent making it harder for a single user to spam the server's Text Chat Singleton. Default values will add up to 1 second of delay per 1000 users in the experience.

Change variable `Rate Limit Length Per Divisor` to alter max delay that can be applied per user increment.

Change variable `Rate Limit Player Divisor` to alter the threshold at which delay is increased.

<figure><img src="/files/byYfEkz4YNcGtB3D1KFs" alt=""><figcaption><p>Client-side rate limiting as seen in BPMC_M2Example_TextChatComponent</p></figcaption></figure>

Additionally, we have functionality on `BPM_M2Example_TextChatSingleton` which also rate limits messages sent to clients, reducing the amount of widgets added per tick.

<figure><img src="/files/ZEDz9HE3twmybwom1YMu" alt=""><figcaption><p>Server-side rate limiting as seen in BPM_M2Example_TextChatSingleton</p></figcaption></figure>

### The text chat component (BPMC\_M2Example\_TextChatComponent)

This component is added to the character's MorpheusActor, and is responsible for communicating with the singleton, sending messages through it, and listening to messages received by it.

### The UI (WBP\_M2Example\_TextChat)

This is the widget added to the example HUD that listens to the text chat component, adding any received messages to the "message history", and sending any messages typed in to the input box (`WBP_M2Example_TextChatInputField`).

`WBP_M2Example_TextChatMessage` and `WBP_M2Example_TextChatInputField` have some added logic to handle adding emojisto the messages.

<figure><img src="/files/DhZXhzwPfaesCBwfHUCX" alt=""><figcaption></figcaption></figure>

#### A note on performance

Adding widgets is a nontrivial operation for the client, so adding a large number of messages in a single tick is going to slow down the client. In this example we have mitigated this with the rate limiting done by the singleton, limiting it so that just a few messages are received per tick.


---

# 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.otherside.xyz/platform-documentation/creation/unreal-development/features-and-tutorials/communication/unreal-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.
