Skip to content

Commit b346242

Browse files
committed
Move the CoreStage::Startup to a seperate StartupSchedule label (#2434)
# Objective - `CoreStage::Startup` is unique in the `CoreStage` enum, in that it represents a `Schedule` and not a `SystemStage`. - This can lead to confusion about how `CoreStage::Startup` and the `StartupStage` enum are related. - Beginners sometimes try `.add_system_to_stage(CoreStage::Startup, setup.system())` instead of `.add_startup_system(setup.system())`, which causes a Panic: ``` thread 'main' panicked at 'Stage 'Startup' does not exist or is not a SystemStage', crates\bevy_ecs\src\schedule\mod.rs:153:13 stack backtrace: 0: std::panicking::begin_panic_handler at /rustc/53cb7b09b00cbea8754ffb78e7e3cb521cb8af4b\/library\std\src\panicking.rs:493 1: std::panicking::begin_panic_fmt at /rustc/53cb7b09b00cbea8754ffb78e7e3cb521cb8af4b\/library\std\src\panicking.rs:435 2: bevy_ecs::schedule::{{impl}}::add_system_to_stage::stage_not_found at .\crates\bevy_ecs\src\schedule\mod.rs:153 3: bevy_ecs::schedule::{{impl}}::add_system_to_stage::{{closure}}<tuple<bevy_ecs::system::function_system::IsFunctionSystem, tuple<bevy_ecs::system::commands::Commands, bevy_ecs::change_detection::ResMut<bevy_asset::assets::Assets<bevy_render::mesh::mesh::Me at .\crates\bevy_ecs\src\schedule\mod.rs:161 4: core::option::Option<mut bevy_ecs::schedule::stage::SystemStage*>::unwrap_or_else<mut bevy_ecs::schedule::stage::SystemStage*,closure-0> at C:\Users\scher\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\option.rs:427 5: bevy_ecs::schedule::Schedule::add_system_to_stage<tuple<bevy_ecs::system::function_system::IsFunctionSystem, tuple<bevy_ecs::system::commands::Commands, bevy_ecs::change_detection::ResMut<bevy_asset::assets::Assets<bevy_render::mesh::mesh::Mesh>>, bevy_ec at .\crates\bevy_ecs\src\schedule\mod.rs:159 6: bevy_app::app_builder::AppBuilder::add_system_to_stage<tuple<bevy_ecs::system::function_system::IsFunctionSystem, tuple<bevy_ecs::system::commands::Commands, bevy_ecs::change_detection::ResMut<bevy_asset::assets::Assets<bevy_render::mesh::mesh::Mesh>>, be at .\crates\bevy_app\src\app_builder.rs:196 7: 3d_scene::main at .\examples\3d\3d_scene.rs:4 8: core::ops::function::FnOnce::call_once<fn(),tuple<>> at C:\Users\scher\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\ops\function.rs:227 ``` ## Solution - Replace the `CoreStage::Startup` Label with the new `StartupSchedule` unit type. Resolves #2229
1 parent f7478f4 commit b346242

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

crates/bevy_app/src/app.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
use crate::{CoreStage, Events, Plugin, PluginGroup, PluginGroupBuilder, StartupStage};
1+
use crate::{
2+
CoreStage, Events, Plugin, PluginGroup, PluginGroupBuilder, StartupSchedule, StartupStage,
3+
};
24
pub use bevy_derive::AppLabel;
35
use bevy_ecs::{
46
prelude::{FromWorld, IntoExclusiveSystem},
@@ -207,7 +209,7 @@ impl App {
207209
/// ```
208210
pub fn add_startup_stage<S: Stage>(&mut self, label: impl StageLabel, stage: S) -> &mut Self {
209211
self.schedule
210-
.stage(CoreStage::Startup, |schedule: &mut Schedule| {
212+
.stage(StartupSchedule, |schedule: &mut Schedule| {
211213
schedule.add_stage(label, stage)
212214
});
213215
self
@@ -238,7 +240,7 @@ impl App {
238240
stage: S,
239241
) -> &mut Self {
240242
self.schedule
241-
.stage(CoreStage::Startup, |schedule: &mut Schedule| {
243+
.stage(StartupSchedule, |schedule: &mut Schedule| {
242244
schedule.add_stage_after(target, label, stage)
243245
});
244246
self
@@ -269,7 +271,7 @@ impl App {
269271
stage: S,
270272
) -> &mut Self {
271273
self.schedule
272-
.stage(CoreStage::Startup, |schedule: &mut Schedule| {
274+
.stage(StartupSchedule, |schedule: &mut Schedule| {
273275
schedule.add_stage_before(target, label, stage)
274276
});
275277
self
@@ -483,7 +485,7 @@ impl App {
483485
system: impl IntoSystemDescriptor<Params>,
484486
) -> &mut Self {
485487
self.schedule
486-
.stage(CoreStage::Startup, |schedule: &mut Schedule| {
488+
.stage(StartupSchedule, |schedule: &mut Schedule| {
487489
schedule.add_system_to_stage(stage_label, system)
488490
});
489491
self
@@ -519,7 +521,7 @@ impl App {
519521
system_set: SystemSet,
520522
) -> &mut Self {
521523
self.schedule
522-
.stage(CoreStage::Startup, |schedule: &mut Schedule| {
524+
.stage(StartupSchedule, |schedule: &mut Schedule| {
523525
schedule.add_system_set_to_stage(stage_label, system_set)
524526
});
525527
self
@@ -588,7 +590,7 @@ impl App {
588590
pub fn add_default_stages(&mut self) -> &mut Self {
589591
self.add_stage(CoreStage::First, SystemStage::parallel())
590592
.add_stage(
591-
CoreStage::Startup,
593+
StartupSchedule,
592594
Schedule::default()
593595
.with_run_criteria(RunOnce::default())
594596
.with_stage(StartupStage::PreStartup, SystemStage::parallel())

crates/bevy_app/src/lib.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ pub use schedule_runner::*;
2020
#[allow(missing_docs)]
2121
pub mod prelude {
2222
#[doc(hidden)]
23-
pub use crate::{app::App, CoreStage, DynamicPlugin, Plugin, PluginGroup, StartupStage};
23+
pub use crate::{
24+
app::App, CoreStage, DynamicPlugin, Plugin, PluginGroup, StartupSchedule, StartupStage,
25+
};
2426
}
2527

2628
use bevy_ecs::schedule::StageLabel;
@@ -30,11 +32,6 @@ use bevy_ecs::schedule::StageLabel;
3032
/// The relative stages are added by [`App::add_default_stages`].
3133
#[derive(Debug, Hash, PartialEq, Eq, Clone, StageLabel)]
3234
pub enum CoreStage {
33-
/// Runs only once at the beginning of the app.
34-
///
35-
/// Consists of the sub-stages defined in [`StartupStage`]. Systems added here are
36-
/// referred to as "startup systems".
37-
Startup,
3835
/// Name of app stage that runs before all other app stages
3936
First,
4037
/// Name of app stage responsible for performing setup before an update. Runs before UPDATE.
@@ -47,6 +44,15 @@ pub enum CoreStage {
4744
/// Name of app stage that runs after all other app stages
4845
Last,
4946
}
47+
48+
/// The label for the Startup [`Schedule`](bevy_ecs::schedule::Schedule),
49+
/// which runs once at the beginning of the app.
50+
///
51+
/// When targeting a [`Stage`](bevy_ecs::schedule::Stage) inside this Schedule,
52+
/// you need to use [`StartupStage`] instead.
53+
#[derive(Debug, Hash, PartialEq, Eq, Clone, StageLabel)]
54+
pub struct StartupSchedule;
55+
5056
/// The names of the default App startup stages
5157
#[derive(Debug, Hash, PartialEq, Eq, Clone, StageLabel)]
5258
pub enum StartupStage {

0 commit comments

Comments
 (0)