Skip to content

[Feature] Component -> Entity Event System #12

Description

@Tweety-Lab

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:

  1. Lifecycle management. Users shouldn't have to worry about disconnecting from events to prevent memory leaks.
  2. 'Run Once' support. Connections to events should have the option to trigger only once before automatically disconnecting.
  3. Explicit Invocation List inspection. Events should expose easily debuggable information about their current connections.
  4. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions