#bevy-plugin #bevy #schedules #plugin #ecs #schedule #order

bevy_schedules_ext

A Bevy plugin for expanding the use of schedules

3 releases

0.13.2 Mar 17, 2024
0.13.1 Feb 29, 2024
0.13.0 Feb 26, 2024

#286 in Game dev

Download history 80/week @ 2024-02-20 210/week @ 2024-02-27 8/week @ 2024-03-05 117/week @ 2024-03-12 36/week @ 2024-03-19 4/week @ 2024-03-26 62/week @ 2024-04-02

170 downloads per month

MIT/Apache

18KB
254 lines

Bevy Schedules, improved

Adds functionality to Bevy's existing Schedules, allowing nesting and using schedules as a replacement for Sets for system grouping and ordering.

Extends Bevy's existing structures, no .add_plugin or managing new Resources.

Features

Nesting

Nest one or more schedules:

With bevy_schedules_ext Vanilla bevy
// Schedules can be added to other schedules
app.add_schedules(Update, Child);
app.add_schedules(Child, (GrandchildOne, GrandchildTwo));

// Add systems to schedules directly, no appending `.in_set(...)` to everything!
app.add_systems(Update, update_system);
app.add_systems(Child, child_system);
app.add_systems(GrandchildOne, grandchild_system_one);
app.add_systems(GrandchildTwo, grandchild_system_two);
// Sets configured manually, Update must be prepended to everything
app.configure_sets(Update, Child);
app.configure_sets(Update, (GrandchildOne, GrandchildTwo).chain().in_set(Child));

// Adding systems to sets requires `.in_set(...)`
app.add_systems(Update, update_system);
app.add_systems(Update, child_system.in_set(Child));
app.add_systems(Update, grandchild_system_one.in_set(GrandchildOne));
app.add_systems(Update, grandchild_system_two.in_set(GrandchildTwo));

All systems will run in Bevy's update loop without having to manually call run on the custom schedules.

A full example is available in examples/nested_schedules.rs.

States

Use Bevy's States as Schedules, so you can add systems to your states and have them run when the state is active, no run conditions needed.

With bevy_schedules_ext Vanilla bevy
// Initialize the state
app.init_schedule_state::<GameState>();

// Add it to our Update loop
app.add_state_to_schedule::<GameState>(Update);

// Add systems to the state
app.add_systems(GameState::Menu, menu_system);
app.add_systems(GameState::Playing, playing_system);
// Initialize the state, pretty much the same
app.init_state::<GameState>();

// Add systems to our update loop, but we need to manually check on every frame if the state is active
app.add_systems(Update, menu_system.run_if(in_state(GameState::Menu)));
app.add_systems(Update, playing_system.run_if(in_state(GameState::Playing)));

Downsides

Since running a schedule requires exclusive world access, schedules can't run in parallel. So any time systems in different groupings need to run in parallel, nesting or using schedule states will block that. Ideally, you'd use a combination of both this crate and vanilla Bevy, with schedules to contain the larger groupings of systems and vanilla Bevy to handle groups that might overlap.

Bevy compatibility

Bevy version bevy_schedules_ext version
0.14.0-dev master branch
0.13 0.13.2

License

All code in this repository is dual-licensed under either:

at your option. This means you can select the license you prefer.

Your contributions

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~7–9.5MB
~172K SLoC