Skip to content

Event trait should not be reused for observers and buffered events #16031

Closed as duplicate of#19564
@alice-i-cecile

Description

@alice-i-cecile

What problem does this solve or what need does it fill?

While the Event trait is required for both observers and buffered events, it's very uncommon to use a single event type as both an observer and a buffered event.
These are used differently and have distinct semantics, despite both representing .

This makes the API more challenging to understand, opens users up to footguns where they create EventReaders for observer events or send buffered events via targeting, and also causes false positives for potential linting tools that attempt to check for things like "all Event types should have a add_event call".

What solution would you like?

Split the trait, keeping the Event trait name for buffered events, and Signal for observer events.

What alternative(s) have you considered?

We could consider unifying the underlying implementations in some way, to allow for users to seamlessly choose between them. That would entail:

  1. Replicating all observer-events to buffered-events, which discards the information about what entity was targeted.
  2. Automatically sending all buffered-events to observers, targeting nothing.

I don't think that this is particularly useful or clear, and has a non-trivial performance overhead. Given that I haven't seen users asking for this, and it can be easily manually implemented if it is desired, I don't think this is the right call.

Additional context

I advocated for adding a marker trait for observer events here. Much bikeshedding followed.

The unification was eventually completed by @cart in #10839 (comment), per #10839 (comment).

I think we should try to unify Event and Trigger with the intent to (ultimately) make normal "buffered" events triggerable.

IMO this change didn't get appropriate consideration due to the extreme length and complexity of that PR and should be reverted :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ECSEntities, components, systems, and eventsC-UsabilityA targeted quality-of-life change that makes Bevy easier to useS-Ready-For-ImplementationThis issue is ready for an implementation PR. Go for it!X-ControversialThere is active debate or serious implications around merging this PR

    Type

    No type

    Projects

    Status

    Observers - Completed

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions