Topic of Discussion
When writing an Entity, there will be many times when a Component needs to notify its owning Entity that something has happened so the Entity can run game logic.
For example, a Door Entity needs to open when it's Button Component detects that it has been pressed. While the component could manually call into it's owner and run an OpenDoor() method, that design quickly becomes problematic.
- Components become reliant on the implementation of their owning Entity.
- Reusing the same Component across different Entities becomes significantly more difficult because it must know every method to call.
- Every new reaction requires modifying the Component instead of simply subscribing to an event.
- Components should not tell Entities how to behave.
Proposed Solution
This is a very common issue across language and engine design that is typically solved using some form of an event system. C# itself has various event types built in, but this proposal introduces an engine-specific event type designed around the needs of game logic.
Our engine Event System has a few requirements:
- Lifecycle management. Users shouldn't have to worry about disconnecting from events to prevent memory leaks.
- 'Run Once' support. Connections to events should have the option to trigger only once before automatically disconnecting.
- Explicit Invocation List inspection. Events should expose easily debuggable information about their current connections.
- Serializable. Events and their connections should be structured in a way that allows easy serialization to text formats. This would enable per-scene Entity -> Entity events in the future.
Topic of Discussion
When writing an Entity, there will be many times when a Component needs to notify its owning Entity that something has happened so the Entity can run game logic.
For example, a
DoorEntity needs to open when it'sButtonComponent detects that it has been pressed. While the component could manually call into it's owner and run anOpenDoor()method, that design quickly becomes problematic.Proposed Solution
This is a very common issue across language and engine design that is typically solved using some form of an event system. C# itself has various event types built in, but this proposal introduces an engine-specific event type designed around the needs of game logic.
Our engine Event System has a few requirements: