Skip to content

Add a "run if any system param changed" run condition (building towards reactivity) #19712

Open
@alice-i-cecile

Description

@alice-i-cecile

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

Various state synchronization systems only need to be run when their inputs have changed.

If we can skip scheduling them, we can save work! However, keeping up with that requires a ton of boilerplate.

What solution would you like?

WARNING: severe hand-waving ahead!

Create a simple ReactiveSystem trait, which caches information about the state of a system last time it ran (things like change ticks and event cursors).

For each system param, define a mechanism for it to check if things have changed. Events would use the event cursor, resource would use change ticks, queries might use the set of matched entities and/or change ticks.

A input_changed run condition would automatically inspect the system parameters, and then create a run condition system that caches and checks all of this information.

What alternative(s) have you considered?

Obviously, these run conditions could be composed manually for each system, by combining our existing run conditions like .resource_changed and .on_event. This isn't particularly ergonomic or maintainable though!

This idea can also be extended via constructing a diff of events / entities between the last and current time the system ran. In flecs, these are called monitors. This allows for a more granular diffing.

Additional context

This idea was inspired by the flecs approach to reactivity via observers, which are effectively "systems that run when their query changes".

While this run condition would be handy in its own right, I think its true value lies in the infrastructure it would require. These concepts of "has this system param changed" could be

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ECSEntities, components, systems, and eventsC-FeatureA new feature, making something new possibleD-ComplexQuite challenging from either a design or technical perspective. Ask for help!S-Needs-Design-DocThis issue or PR is particularly complex, and needs an approved design doc before it can be merged

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions