Skip to content

Chat System

💬 Simple AES Chat (Focus + Whisper Walkthrough)

Section titled “💬 Simple AES Chat (Focus + Whisper Walkthrough)”

This example shows a minimal multiplayer chat using a single AES Event (AES_ChatMessage) plus 5 supporting Blueprints. Core ideas:

  • A Whisper hop PlayerController → GameState (server) followed by a multicast.
  • A local Focus path so the Player Controller hears HUD‑originated messages before relaying them.
  • Re‑generation on each client (fan‑out) so UI stays decoupled from RPC details.

Instead of a squished table, here’s a card grid:

1. AES_ChatMessage Event

Single AES Event carrying User + Message.

  • Mark both fields Instance Editable & Expose on Spawn.
  • Gives pins on Generate Event.

2. GM_ChatDemo GameMode

Glue class that designates GS_ChatDemo + PC_Chatter. No extra logic.

3. GS_ChatDemo GameState

Owns stable Identity (Object ID = GameState), listens for Whisper chat, multicast → re‑generate locally.

  • Registers Whisper for AES_ChatMessage.
  • Multicast MC_ChatMessage fan‑out.

4. PC_Chatter PlayerController

Local input + bridge to server. Focus‑listens for HUD messages (broadcaster ChatHud).

  • RPC SR_SendMessage → server Whisper to GameState.
  • Spawns HUD if locally controlled.

5. W_ChatHUD Widget

Text entry + scroll list. Generates local (no target) events; also Focus‑listens to GameState re‑broadcast.

  • Identity with Object ID = ChatHud.
  • Creates & focuses input; sends on Enter / button.

6. W_ChatMessage Widget

Visual row; fade in → delay → fade out, then remove.

  • Sets User: prefix & message text.

  1. Right‑click → AESEvent → name it AES_ChatMessage.
  2. Add 2 properties:
  • User (Name or String) – set Instance Editable + Expose on Spawn.
  • Message (String / Text) – also Instance Editable + Expose on Spawn.

Chat Message Event

Because the properties are exposed, the Generate Event node will give you pins for User + Message when you pick this Event Class.


Very simple: in the world settings, set Default Game State Class to GS_ChatDemo and Player Controller Class to PC_Chatter. (Any default pawn is fine / irrelevant.)

Game Mode World Settings


Responsibilities:

  1. On Begin Play call Generate Identity with:
  • Object = Self
  • Object ID = GameState (hard-coded label so clients & server agree; there is only one Game State instance).
  1. Register for Whisper of AES_ChatMessage (using the Identity you just generated) – this lets the server receive direct chat events targeted at the Game State.
  2. Implement a custom event MC_ChatMessage marked Multicast (reliable optional) with params: User (Name) & Message (String/Text).
  3. When AES_ChatMessage Whisper arrives on server:
  • Extract its payload (User, Message).
  • Call MC_ChatMessage(User, Message) so every client (including sender) hears it.
  1. Inside MC_ChatMessage on each client:
  • Call Generate Event (no Target Id) with Event = AES_ChatMessage, filling the same User + Message. This turns the network replication into a local broadcast path so UI elements (e.g. Focus registrations) can respond uniformly.

Game State Overview


Responsibilities:

  1. On Begin PlayGenerate Identity (no Object ID needed, let it be unique per player).
  2. If Is Local Controller:
  • Create and add a W_ChatHUD to viewport.
  1. Register for Focus for AES_ChatMessage where Broadcaster ID = ChatHud. (You will generate an Identity in the HUD with that Object ID, making it the broadcaster for local typed messages.)
  2. Custom Event SR_SendMessage (RunOnServer) with params User + Message.
  • On server: Call Generate Event for AES_ChatMessage with Target Id = GameState (the Game State’s Identity ID) so it arrives as a Whisper and triggers the server’s registration.
  1. Local handling of HUD-origin messages: when the Focus registration fires (HUD generated an event without target), call SR_SendMessage to hop to server.

Flow so far (local player typing): W_ChatHUD (Generate Event no target) → Focus hit in PC_ChatterSR_SendMessage → Server → Generate Event (Target Id = GameState) → GS_ChatDemo Whisper → MC_ChatMessage → All clients → each client re‑generates (no target) → their UIs respond.

Player Controller Overview


UI Elements (suggested):

  • ScrollBox (messages container)
  • EditableTextBox (TXT_Message)
  • Button (BTN_Send)

Setup on Construct / Begin Play:

  1. Generate Identity with Object ID = ChatHud (important – matches the Focus listener in the Player Controller).
  2. Register for Focus of AES_ChatMessage with Broadcaster ID = GameState so it hears messages fanned out after the multicast re‑generation.
  3. Show mouse cursor (via owning Player Controller) & set keyboard focus to the text box.

Sending a message (two entry points):

  • On Text Box OnTextCommitted (OnEnter) – if not empty
  • On BTN_Send clicked – if not empty

Then:

  1. Grab Player State name (or fallback like “You”).
  2. Call Generate Event (Event = AES_ChatMessage) without Target Id and fill User + Message.
  • Player Controller hears it (Focus: broadcaster = ChatHud) and triggers the server path.
  1. Clear the text box & refocus it.

Receiving messages from Game State:

  • Focus registration (broadcaster = GameState) fires when Game State re‑generates after multicast.
  • Create a W_ChatMessage widget, set its User & Message, add to ScrollBox, then scroll to end.

Chat Hud Design Chat Hud Overview


On Construct:

  1. Set TXT_User to User + ":" (or style as you like) and TXT_Message to message text.
  2. Play a FadeIn animation.
  3. Delay (e.g. 10s) then play FadeOut; on animation finished remove self.

Chat Message Design Chat Message Overview


ActionGenerate Event CallTarget IdWho Listens
User types locallyAES_ChatMessage(none)Player Controller (Focus: ChatHud)
PC → Server(RPC only)
Server relays to GSAES_ChatMessageGameStateGame State (Whisper)
Server → clients(Multicast RPC)All clients run handler
Clients re-fan-outAES_ChatMessage(none)Local HUD Focus (GameState) + any other listeners

SymptomLikely CauseFix
No messages appear anywhereGame State Identity not generated or wrong Target Id usedEnsure GS sets Object ID = GameState & server PC uses that Identity ID as Target
HUD never triggers serverPC not Focus-registered for broadcaster ChatHudVerify Focus registration broadcaster ID = ChatHud
Messages only local, no replicationForgot SR_SendMessage RPC or Whisper generation stepEnsure PC server RPC runs & generates with Target Id
Messages duplicatedMultiple Focus registrations or re‑generation done twiceCheck you only re‑generate inside multicast once

You built a pipeline that:

  1. Generates per‑object Identities (HUD, PC, Game State) with intentional Object IDs where needed (ChatHud, GameState).
  2. Uses Focus (no Target Id generation) for local HUD → Player Controller message origination.
  3. Uses Whisper (Target Id = GameState) for authoritative server ingestion.
  4. Multicasts & re‑generates (no target) to create a uniform UI consumption path.

That’s the full loop—concise, network aware, and a clean example of Focus + Whisper interop.