bevy_schedules_ext

Crates.iobevy_schedules_ext
lib.rsbevy_schedules_ext
version0.13.2
sourcesrc
created_at2024-02-26 16:59:40.383506
updated_at2024-03-17 21:26:43.159974
descriptionA Bevy plugin for expanding the use of schedules.
homepage
repositoryhttps://github.com/vonforum/bevy_schedules_ext
max_upload_size
id1153970
size50,986
(vonforum)

documentation

README

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.

Commit count: 61

cargo fmt