From b715172dce08830126052a89ad6a985b8275ddfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=9E=97=E4=BC=9F?= Date: Wed, 16 Aug 2023 02:53:58 +0800 Subject: [PATCH] Move scene spawner systems to SpawnScene schedule (#9260) # Objective - Fixes https://github.com/bevyengine/bevy/issues/9250 ## Changelog - Move scene spawner systems to a new SpawnScene schedule which is after Update and before PostUpdate (schedule order: [PreUpdate][Update][SpawnScene][PostUpdate]) ## Migration Guide - Move scene spawner systems to a new SpawnScene schedule which is after Update and before PostUpdate (schedule order: [PreUpdate][Update][SpawnScene][PostUpdate]), you might remove system ordering code related to scene spawning as the execution order has been guaranteed by bevy engine. --------- Co-authored-by: Hennadii Chernyshchyk --- crates/bevy_app/src/main_schedule.rs | 6 ++++++ crates/bevy_scene/src/lib.rs | 7 +++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/crates/bevy_app/src/main_schedule.rs b/crates/bevy_app/src/main_schedule.rs index c940fda5337b9..ff482b3e98b0f 100644 --- a/crates/bevy_app/src/main_schedule.rs +++ b/crates/bevy_app/src/main_schedule.rs @@ -79,6 +79,11 @@ pub struct FixedUpdate; #[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)] pub struct Update; +/// The schedule that contains scene spawning. +/// This is run by the [`Main`] schedule. +#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)] +pub struct SpawnScene; + /// The schedule that contains logic that must run after [`Update`]. For example, synchronizing "local transforms" in a hierarchy /// to "global" absolute transforms. This enables the [`PostUpdate`] transform-sync system to react to "local transform" changes in /// [`Update`] without the [`Update`] systems needing to know about (or add scheduler dependencies for) the "global transform sync system". @@ -112,6 +117,7 @@ impl Default for MainScheduleOrder { Box::new(StateTransition), Box::new(RunFixedUpdateLoop), Box::new(Update), + Box::new(SpawnScene), Box::new(PostUpdate), Box::new(Last), ], diff --git a/crates/bevy_scene/src/lib.rs b/crates/bevy_scene/src/lib.rs index e3ca8a2fee573..655675e3f32de 100644 --- a/crates/bevy_scene/src/lib.rs +++ b/crates/bevy_scene/src/lib.rs @@ -11,6 +11,7 @@ mod scene_spawner; #[cfg(feature = "serialize")] pub mod serde; +use bevy_ecs::schedule::IntoSystemConfigs; pub use bundle::*; pub use dynamic_scene::*; pub use dynamic_scene_builder::*; @@ -27,7 +28,7 @@ pub mod prelude { }; } -use bevy_app::prelude::*; +use bevy_app::{prelude::*, SpawnScene}; use bevy_asset::AddAsset; #[derive(Default)] @@ -40,9 +41,7 @@ impl Plugin for ScenePlugin { .add_asset::() .init_asset_loader::() .init_resource::() - .add_systems(Update, scene_spawner_system) - // Systems `*_bundle_spawner` must run before `scene_spawner_system` - .add_systems(PreUpdate, scene_spawner); + .add_systems(SpawnScene, (scene_spawner, scene_spawner_system).chain()); } }