Skip to content

Commit a91f89d

Browse files
committed
Add a basic example for system ordering (#7017)
# Objective Fix #5653. ## Solution - Add an example of how systems can be ordered from within a stage. - Update some docs from before #4224
1 parent 65d3901 commit a91f89d

File tree

1 file changed

+29
-3
lines changed
  • crates/bevy_ecs/src/system

1 file changed

+29
-3
lines changed

crates/bevy_ecs/src/system/mod.rs

+29-3
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,35 @@
4141
//!
4242
//! - **System Stages:** They determine hard execution synchronization boundaries inside of
4343
//! which systems run in parallel by default.
44-
//! - **Labeling:** First, systems are labeled upon creation by calling `.label()`. Then,
45-
//! methods such as `.before()` and `.after()` are appended to systems to determine
46-
//! execution order in respect to other systems.
44+
//! - **Labels:** Systems may be ordered within a stage using the methods `.before()` and `.after()`,
45+
//! which order systems based on their [`SystemLabel`]s. Each system is implicitly labeled with
46+
//! its `fn` type, and custom labels may be added by calling `.label()`.
47+
//!
48+
//! [`SystemLabel`]: crate::schedule::SystemLabel
49+
//!
50+
//! ## Example
51+
//!
52+
//! ```
53+
//! # use bevy_ecs::prelude::*;
54+
//! # let mut app = SystemStage::single_threaded();
55+
//! // Prints "Hello, World!" each frame.
56+
//! app
57+
//! .add_system(print_first.before(print_mid))
58+
//! .add_system(print_mid)
59+
//! .add_system(print_last.after(print_mid));
60+
//! # let mut world = World::new();
61+
//! # app.run(&mut world);
62+
//!
63+
//! fn print_first() {
64+
//! print!("Hello");
65+
//! }
66+
//! fn print_mid() {
67+
//! print!(", ");
68+
//! }
69+
//! fn print_last() {
70+
//! println!("World!");
71+
//! }
72+
//! ```
4773
//!
4874
//! # System parameter list
4975
//! Following is the complete list of accepted types as system parameters:

0 commit comments

Comments
 (0)