Game Messages

Game Messages inheritance structure

This is (only) the "top" of the GameMessage inheritance hierarchy. All game messages inherit from GameMessage.

diagram

Explanation:

ActorMessage (and it’s inheritors) is meant to only be received by the Actor system and not for triggering any additional game logic.

The MessageBus

The MessageBus works per the publish/subscribe pattern.

Listening to GameMessages

Users of the Engine should not have to worry about issuing (posting) GameMessages, as it is an internal working, but if you want to extend the engine, maybe receiving (listening for) messages comes in handy.

To listen for a specific message type you can write:

MessageBus.Singleton.OfType<PickupCollideWithUnit>().Subscribe(OnPickupCollideWithUnit);

private static void OnPickupCollideWithUnit(PickupCollideWithUnit message){

}
The MessageBus works synchronously. This has the advantage that when a call to MessageBus.Post(myMessage) returns, all side effects of the message have already occurred. However, it must be noted that performance is crucial inside code blocks that react to GameMessages.