Easy Multiplayer
  • Welcome
  • Messenger
    • Overview
    • Concept
    • Getting Started
    • Redirection
    • Serialization
    • Samples
  • Utils
    • MultiplayerUtils
Powered by GitBook
On this page
  • Explanation
  • Example
  1. Messenger

Concept

PreviousOverviewNextGetting Started

Last updated 6 months ago

Explanation

Messages utilize the concept of singularity, as they are primarily designed for manager classes and systems within your game. Unlike RPCs, which are meant to synchronize large amounts of data between the client and server (such as movement, health, or power-ups), the messaging system focuses on important functionalities, like a ready-up system, a vote kick system, or sending out a server's complex configuration class.

The singularity concept ensures that only one instance of a particular type can execute a message at a time, except for static messages, which do not require an instance. This means that if you have a player message for each player controller, only one of those controllers will be able to run the message.

Conversely, if you have a single PlayerManager class for each player, the message will be executed on that single PlayerManager instance.

Reminder: Static messages do not need an instance to register!

Example

Here is an example on how to register an instance.

private void Awake()
{
    // "this" is the instance,
    // that we want to use when a message within the instance gets executed.

    // You can register instance anytime,
    // aslong as you do it before you call the message!
    Messenger.RegisterInstance(this);
    
    // Instances can also be registered per message method.
    Messenger.RegisterInstance(this, nameof(HelloMessage));
}