Run individual SystemSets in Schedules
#21893
Open
+543
−6
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Objective
Bevy users occasionally ask for the ability to run specific
SystemSets in aSchedule, commonly for unit testing behaviors. Beyond that, this functionality brings us closer to turning ourUpdate,PostUpdate, etc schedules into system sets by giving system sets a power that previously only schedules had: the ability to be executed.Solution
SystemExecutor::run:subgraph: Option<SystemSetKey>Some, the providedSystemSetKeyis used to fetch a bitset of the systems that are part of the set (including transitively), which is used to filter theSystemExecutorto execute only those systems.None, theSystemExecutorfunctions as previously.SystemSchedule::systems_in_setwhich holds a sparse mapping of system sets to bitsets of the systems part of that set.Schedule::run_system_setwhich invokesSystemExecutor::runwith the given system set.World/Commands::run_system_set/try_run_system_setwhich invokesSchedule::run_system_set.Note:
Schedule::run_system_setis not re-entrant.Testing
Future work
slotmap::SparseSecondaryMapwork under alloc rather than std, so we can replaceSystemSchedule::systems_in_sets'sHashMapwith it.Showcase
You can now run a specific system set within a schedule without executing the entire
schedule! This is particularly useful for testing, debugging, or selectively running
parts of your game logic, all without needing to factor features out into separate
schedules: