Defining Events
Events are plain Go structs that embedBaseEvent and implement the Event interface. This interface requires a single Name() method that returns a unique string identifier.
Emitting Events
Just like with commands, you must declare the events a system emits in its state struct. Add aWithEvent[T] field to your system state type, where T is your event type:
Emit to emit the event:
Just like with commands, a system cannot have multiple
WithEvent fields with the same event type.Subscribing to Events
Events emitted during a tick are collected and broadcast to subscribers at the end of that tick. While events are broadcast, clients must explicitly subscribe to receive them. Subscribe to an event by passing the event name and a handler function:- Unity C#
- TypeScript
- Unity C#
- TypeScript