bevy/release-content/migration-guides/schedule_slotmaps.md
Christian Hughes ebf87f56ef
Use SlotMaps to store systems and system sets in Schedules (#19352)
# Objective

- First step towards #279

## Solution

Makes the necessary internal data structure changes in order to allow
system removal to be added in a future PR: `Vec`s storing systems and
system sets in `ScheduleGraph` have been replaced with `SlotMap`s.

See the included migration guide for the required changes.

## Testing

Internal changes only and no new features *should* mean no new tests are
requried.
2025-07-03 18:50:54 +00:00

1.5 KiB

title pull_requests
Schedule SlotMaps
19352

In order to support removing systems from schedules, Vecs storing Systems and SystemSets have been replaced with SlotMaps which allow safely removing and reusing indices. The maps are respectively keyed by SystemKeys and SystemSetKeys.

The following signatures were changed:

  • NodeId::System: Now stores a SystemKey instead of a plain usize
  • NodeId::Set: Now stores a SystemSetKey instead of a plain usize
  • ScheduleBuildPass::collapse_set: Now takes the type-specific keys. Wrap them back into a NodeId if necessary.
  • The following functions now return the type-specific keys. Wrap them back into a NodeId if necessary.
    • Schedule::systems
    • ScheduleGraph::systems
    • ScheduleGraph::system_sets
    • ScheduleGraph::conflicting_systems
  • Use the appropriate key types to index these structures rather than bare usizes:
    • ScheduleGraph::systems field
    • ScheduleGraph::system_conditions
  • The following functions now take the type-specific keys. Use pattern matching to extract them from NodeIds, if necessary:
    • ScheduleGraph::get_system_at
    • ScheduleGraph::system_at
    • ScheduleGraph::get_set_at
    • ScheduleGraph::set_at
    • ScheduleGraph::get_set_conditions_at
    • ScheduleGraph::set_conditions_at

The following functions were removed:

  • NodeId::index: You should match on and use the SystemKey and SystemSetKey instead.
  • NodeId::cmp: Use the PartialOrd and Ord traits instead.