Unreal Text Chat
Last updated
Was this helpful?
Last updated
Was this helpful?
In The M2 Example Plugin, 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.
NOTE: This example text chat system has been scale tested, and should work for medium scale projects of up to a few thousand players. It is not suitable for massive scale worlds, due to the load on the server - if you are wanting text chat in an experience with more than a few thousand players, you would need to use an external service, like PubNub.
You can talk with the Solutions Engineering team to get guidance on how to implement this for your project.
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.
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)
To hit the aforementioned scaletest
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.
Currently the component has backwards compatibility with the old PubNub Text Chat component, allowing the component to send messages through that system instead, if UsingPubnubChat
is set to true.
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.
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.