docs
Systems
Messaging
EventSystem
Architecture and Design

Design Patterns:

The system uses a broadcast messaging pattern where events are routed to multiple handlers based on their target domain. The EventBus (from dependencies) maintains a mapping of domains to handler lists and delivers each event to all subscribed handlers in order.

Event Flow:

  1. A system creates an event via EventFactory.CreateEvent(domain, verb)
  2. The event is populated with parameters using event.Params.Set(key, value)
  3. The event is raised via eventBus.Raise(event)
  4. EventBus extracts the TargetDomain from the event
  5. All handlers subscribed to that domain receive the event

Key Concepts:

  • Domain: An enum value identifying which system should handle the event (UI, Audio, VFX, etc.)
  • Verb: An integer representing the specific action or command within a domain, defined by the feature's contracts
  • Params: A type-safe parameter container holding event payload data using ParamKey<T> instances
  • IEvent: A marker interface that all event types must implement to be recognized by the routing system

Connection to Dependencies:

  • EventBus is the actual router; it is obtained from the global ServiceLocator
  • Params is used internally by Event to store its payload
  • Domain and ParamKey<T> come from the Contracts system and provide the typing and routing identifiers
  • IEventReceiver is implemented by handler classes that listen for events

Thread Safety:

The EventBus documentation notes that Subscribe and Raise are called from the main thread, so no additional synchronization is required within EventSystem itself.