Skip to content

move time update to after everything #4728

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions crates/bevy_app/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ pub struct App {
pub runner: Box<dyn Fn(App)>,
/// A container of [`Stage`]s set to be run in a linear order.
pub schedule: Schedule,
/// A stage run after main schedule and sub app schedules
pub final_stage: SystemStage,
sub_apps: HashMap<Box<dyn AppLabel>, SubApp>,
}

Expand Down Expand Up @@ -98,6 +100,7 @@ impl App {
Self {
world: Default::default(),
schedule: Default::default(),
final_stage: SystemStage::single_threaded(),
runner: Box::new(run_once),
sub_apps: HashMap::default(),
}
Expand All @@ -115,6 +118,7 @@ impl App {
for sub_app in self.sub_apps.values_mut() {
(sub_app.runner)(&mut self.world, &mut sub_app.app);
}
self.final_stage.run(&mut self.world);
}

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

/// Adds a system to the final stage that runs after the app and render schedules.
pub fn add_system_to_final_stage<Params>(
&mut self,
system: impl IntoSystemDescriptor<Params>,
) -> &mut Self {
self.final_stage.add_system(system);
self
}

/// Adds a [`SystemSet`] to the [update stage](Self::add_default_stages).
///
/// # Examples
Expand Down
11 changes: 6 additions & 5 deletions crates/bevy_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,12 @@ impl Plugin for CorePlugin {
.register_type::<Name>()
.register_type::<Range<f32>>()
.register_type::<Timer>()
// time system is added as an "exclusive system" to ensure it runs before other systems
// in CoreStage::First
.add_system_to_stage(
CoreStage::First,
time_system.exclusive_system().label(CoreSystem::Time),
// time system is added as an "exclusive system at end" to ensure it runs after other systems
.add_system_to_final_stage(
time_system
.exclusive_system()
.at_end()
.label(CoreSystem::Time),
);

register_rust_types(app);
Expand Down