FChatMessage
Overview
FChatMessage is a structure used to store and manage individual chat messages. It includes properties for the sender's name, message content, timestamp, and a unique identifier. The structure also provides delegates for pre-replicated remove, post-replicated add, and post-replicated change events.
Properties
Type | Name | Access | Description |
|---|---|---|---|
FString | SenderName | BlueprintReadOnly | The name of the sender of the message. |
FString | MessageContent | BlueprintReadOnly | The content of the chat message. |
FDateTime | Timestamp | BlueprintReadOnly | The timestamp when the message was sent. |
FGuid | Id | BlueprintReadOnly | A unique identifier for the message. |
Functions
Return Type | Signature | Description |
|---|---|---|
void | PreReplicatedRemove(const FFastArraySerializer& InArraySerializer) | Invoked before a chat message is removed from the array. Executes any bound pre-replicated remove delegate. |
void | PostReplicatedAdd(const FFastArraySerializer& InArraySerializer) | Invoked after a new chat message is added to the array. Executes any bound post-replicated add delegate. |
void | PostReplicatedChange(const FFastArraySerializer& InArraySerializer) | Invoked after a chat message in the array is changed. Executes any bound post-replicated change delegate. |
FMessageArrayContainer
Overview
FMessageArrayContainer is a structure that holds an array of FChatMessage objects and implements network delta serialization to efficiently transmit changes over the network.
Properties
Type | Name | Access | Description |
|---|---|---|---|
TArray | Items | None | The array of chat messages. |
Functions
Return Type | Signature | Description |
|---|---|---|
bool | NetDeltaSerialize(FNetDeltaSerializeInfo& DeltaParams) | Serializes the changes in the array of chat messages for network transmission. |
ALimenChatHandler
Overview
ALimenChatHandler is a class that extends ALimenGameplayManager and manages the lifecycle of chat messages. It includes functionality to register new messages, retrieve all messages, and handle replication of these messages across the network.
Properties
Type | Name | Access | Description |
|---|---|---|---|
FMessageArrayContainer | ChatMessages | ReplicatedUsing=OnRep_ChatMessages | The container for chat messages that is replicated. |
Functions
Return Type | Signature | Description |
|---|---|---|
void | BeginPlay() | Initializes the chat handler when the game starts. |
void | GetLifetimeReplicatedProps(TArray & OutLifetimeProps) const | Specifies which properties should be replicated across the network. |
void | RegisterMessage(const FChatMessage& InMessage) | Registers a new chat message and notifies clients if running on a dedicated server. |
TArray | GetChatMessages() const | Retrieves all current chat messages. |
void | OnRep_ChatMessages() | Handles the replication of chat messages, sorting them by timestamp and broadcasting the last received message to clients. |
Usage & Implementation Notes
The class is designed to be replicated across the network, ensuring that all players receive updates on new chat messages.
Chat messages are sorted by their timestamp upon replication to maintain chronological order.
The
RegisterMessagefunction broadcasts new messages only if the game is running on a dedicated server.