Skip to content

Triggered systems #1273

@alice-i-cecile

Description

@alice-i-cecile

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

Some behavior may require immediate handling at the next available opportunity, rather than waiting until the next frame comes around. This may be useful for handling input events, or chaining systems for things like error recovery.

What solution would you like?

When a certain behavior occurs (such as an event of a specific type being generated like for input), a run-once handling system is dynamically inserted into the pool of systems that are set to be run, possibly with increased priority.

It's unclear if the triggering behavior can or should be limited to Events in the Bevy sense.

What alternative(s) have you considered?

Systems can be run once per tick in the standard fashion and consume events. This is often too slow, especially when chained.

A copy of the appropriate system can be manually inserted immediately after every possible system that could trigger it, and then return early. This is error-prone and tedious.

Additional context

Implementing this would require changes to the scheduler, to allow for dynamic insertion of systems on a one-time basis mid-stage. As is, systems are not at added at runtime in the existing code base, and the scheduler constructs a complete list of systems at the beginning of the stage.

This pattern relates to but is distinct from event-dependent run criteria, discussed in #1272.

This pattern may be helpful for refreshing indexes, as discussed in #1205. This is particularly true if systems could be inserted dynamically immediately before a given system was scheduled to run.

This pattern would be useful for handling UI chains in a timely fashion, although the ergonomics might be painful.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ECSEntities, components, systems, and eventsC-FeatureA new feature, making something new possible

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions