docs
Systems
Messaging
EventSystem
Key Components

EventFactory

EventFactory is a static utility that constructs new Event instances. It abstracts event creation and ensures consistent initialization. Call CreateEvent(domain, verbValue) when a system needs to send a message to another domain.

EventFactory.CreateEvent(Domain.Audio, 42).Params.Set(key, value);

Event

Event is the core message type in EventSystem. Each event holds:

  • A TargetDomain that determines which handler receives it
  • A Verb code identifying the specific action within that domain
  • A Params payload containing typed data

Systems populate the payload using:

myEvent.Params.Set(CoreParamKeys.StringValue, "hello");
string retrieved = myEvent.Params.Get(CoreParamKeys.StringValue);

Internally, Params is a dictionary-backed container using IParamKey as keys and boxed objects as values. Type safety is enforced through ParamKey<T> generics.


IEvent and IEventReceiver

IEvent is a marker interface that all events must implement. This allows EventBus to route any event-like object generically.

IEventReceiver defines the contract for listeners. Handlers implement OnEvent(Event e) to receive and process dispatched events:

public class MyAudioHandler : IEventReceiver
{
    public void OnEvent(Event e)
    {
        if (e.Verb == AudioVerbs.PlaySound)
        {
            // handle the event
        }
    }
}

Interaction Flow:

  1. MyAudioHandler registers with EventBus (via subscription, obtained from ServiceLocator.GetBusRegistry().EventBus)
  2. A feature creates an event: EventFactory.CreateEvent(Domain.Audio, AudioVerbs.PlaySound)
  3. The event is populated: event.Params.Set(key, value)
  4. The event is raised: eventBus.Raise(event)
  5. EventBus routes it to all handlers subscribed to Domain.Audio
  6. MyAudioHandler.OnEvent(event) is called
  7. The handler retrieves parameters and executes its logic

The Params system ensures type-safe retrieval through generic casting; ParamKey<T> instances provide compile-time checking that the expected type matches.