Skip to content

Advanced pattern: entities-as-events #15

@alice-i-cecile

Description

@alice-i-cecile

I'm currently using this for extremely complex combat events in Fonts of Power.

The core idea here is that rather than emitting an event, you spawn an entity with a marker component, and then look for that in your "event-handling" systems. This has a few nice advantages:

  1. You can make lists of various "events" in a heterogenous fashion without needing to resort to trait objects. This is what forced me to switch in the first place.
  2. The "events" can be incredibly heterogenous, letting you add only the relevant fields to the specific event emitted.
  3. You can change the fields present on each event on the fly.
  4. You can perform complex operations with overlapping systems, touching only the events that have the right fields (in this case, components on your event-entity).
  5. No need for complex generics.

It also has a few critical disadvantages:

  1. Unlike true events, event-entities aren't spawned immediately.
  2. Ditto for adding and removing components.
  3. Much higher conceptual overhead in simple cases.
  4. Cleanup must be handled manually.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-enhancementNew content that isn't covered alreadyS-programmingCore bevy APIs / programming patternsZ-largelarge task that needs a significant time investment

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions