diff --git a/crates/bevy_app/src/app.rs b/crates/bevy_app/src/app.rs index a5990581558054..ce9370ec74dd8e 100644 --- a/crates/bevy_app/src/app.rs +++ b/crates/bevy_app/src/app.rs @@ -58,7 +58,7 @@ pub struct App { sub_apps: HashMap, SubApp>, /// A private marker to prevent incorrect calls to `App::run()` from `Plugin::build()` /// - is_from_plugin_build: bool, + is_building_plugin: bool, } /// Each [`SubApp`] has its own [`Schedule`] and [`World`], enabling a separation of concerns. @@ -102,7 +102,7 @@ impl App { schedule: Default::default(), runner: Box::new(run_once), sub_apps: HashMap::default(), - is_from_plugin_build: false, + is_building_plugin: false, } } @@ -133,8 +133,8 @@ impl App { let _bevy_app_run_guard = bevy_app_run_span.enter(); let mut app = std::mem::replace(self, App::empty()); - if app.is_from_plugin_build { - panic!("App::Run() is called from a Plugin::Build(), which might result in other initialization code not run."); + if app.is_building_plugin { + panic!("App::run() was called from within Plugin::Build(), which is not allowed."); } let runner = std::mem::replace(&mut app.runner, Box::new(run_once)); (runner)(app); @@ -769,9 +769,9 @@ impl App { T: Plugin, { debug!("added plugin: {}", plugin.name()); - self.is_from_plugin_build = true; + self.is_building_plugin = true; plugin.build(self); - self.is_from_plugin_build = false; + self.is_building_plugin = false; self } @@ -797,8 +797,10 @@ impl App { /// ``` pub fn add_plugins(&mut self, mut group: T) -> &mut Self { let mut plugin_group_builder = PluginGroupBuilder::default(); + self.is_building_plugin = true; group.build(&mut plugin_group_builder); plugin_group_builder.finish(self); + self.is_building_plugin = false; self }