Skip to content

Commit 2166c90

Browse files
committed
move time update to after render schedule
1 parent ae580e5 commit 2166c90

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

crates/bevy_app/src/app.rs

+13
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ pub struct App {
5656
pub runner: Box<dyn Fn(App)>,
5757
/// A container of [`Stage`]s set to be run in a linear order.
5858
pub schedule: Schedule,
59+
/// A stage run after main schedule and sub app schedules
60+
pub final_stage: SystemStage,
5961
sub_apps: HashMap<Box<dyn AppLabel>, SubApp>,
6062
}
6163

@@ -98,6 +100,7 @@ impl App {
98100
Self {
99101
world: Default::default(),
100102
schedule: Default::default(),
103+
final_stage: SystemStage::single_threaded(),
101104
runner: Box::new(run_once),
102105
sub_apps: HashMap::default(),
103106
}
@@ -115,6 +118,7 @@ impl App {
115118
for sub_app in self.sub_apps.values_mut() {
116119
(sub_app.runner)(&mut self.world, &mut sub_app.app);
117120
}
121+
self.final_stage.run(&mut self.world);
118122
}
119123

120124
/// Starts the application by calling the app's [runner function](Self::set_runner).
@@ -326,6 +330,15 @@ impl App {
326330
self.add_system_to_stage(CoreStage::Update, system)
327331
}
328332

333+
/// Adds a system to the final stage that runs after the app and render schedules.
334+
pub fn add_system_to_final_stage<Params>(
335+
&mut self,
336+
system: impl IntoSystemDescriptor<Params>,
337+
) -> &mut Self {
338+
self.final_stage.add_system(system);
339+
self
340+
}
341+
329342
/// Adds a [`SystemSet`] to the [update stage](Self::add_default_stages).
330343
///
331344
/// # Examples

crates/bevy_core/src/lib.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,12 @@ impl Plugin for CorePlugin {
5454
.register_type::<Name>()
5555
.register_type::<Range<f32>>()
5656
.register_type::<Timer>()
57-
// time system is added as an "exclusive system" to ensure it runs before other systems
58-
// in CoreStage::First
59-
.add_system_to_stage(
60-
CoreStage::First,
61-
time_system.exclusive_system().label(CoreSystem::Time),
57+
// time system is added as an "exclusive system at end" to ensure it runs after other systems
58+
.add_system_to_final_stage(
59+
time_system
60+
.exclusive_system()
61+
.at_end()
62+
.label(CoreSystem::Time),
6263
);
6364

6465
register_rust_types(app);

0 commit comments

Comments
 (0)