Skip to content

Commit 5c7abb0

Browse files
Remove OnUpdate system set (#8260)
# Objective - Fixes #8239. ## Solution - Replace `OnUpdate` with `run_if(in_state(xxx))`. --- ## Migration Guide - Replace `OnUpdate` with `run_if(in_state(xxx))`. --------- Co-authored-by: Alice Cecile <[email protected]>
1 parent b423e6e commit 5c7abb0

File tree

8 files changed

+13
-31
lines changed

8 files changed

+13
-31
lines changed

crates/bevy_app/src/app.rs

-8
Original file line numberDiff line numberDiff line change
@@ -312,10 +312,6 @@ impl App {
312312
/// [`run_once`](`run_once_condition`) condition to run the on enter schedule of the
313313
/// initial state.
314314
///
315-
/// This also adds an [`OnUpdate`] system set for each state variant,
316-
/// which runs during [`Update`] after the transitions are applied.
317-
/// These system sets only run if the [`State<S>`] resource matches the respective state variant.
318-
///
319315
/// If you would like to control how other systems run based on the current state,
320316
/// you can emulate this behavior using the [`in_state`] [`Condition`](bevy_ecs::schedule::Condition).
321317
///
@@ -333,10 +329,6 @@ impl App {
333329
.chain(),
334330
);
335331

336-
for variant in S::variants() {
337-
self.configure_set(Update, OnUpdate(variant.clone()).run_if(in_state(variant)));
338-
}
339-
340332
// The OnEnter, OnExit, and OnTransition schedules are lazily initialized
341333
// (i.e. when the first system is added to them), and World::try_run_schedule is used to fail
342334
// gracefully if they aren't present.

crates/bevy_ecs/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub mod prelude {
4040
schedule::{
4141
apply_state_transition, apply_system_buffers, common_conditions::*, Condition,
4242
IntoSystemConfigs, IntoSystemSet, IntoSystemSetConfig, IntoSystemSetConfigs, NextState,
43-
OnEnter, OnExit, OnTransition, OnUpdate, Schedule, Schedules, State, States, SystemSet,
43+
OnEnter, OnExit, OnTransition, Schedule, Schedules, State, States, SystemSet,
4444
},
4545
system::{
4646
adapter as system_adapter,

crates/bevy_ecs/src/schedule/state.rs

+1-11
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::mem;
44

55
use crate as bevy_ecs;
66
use crate::change_detection::DetectChangesMut;
7-
use crate::schedule::{ScheduleLabel, SystemSet};
7+
use crate::schedule::ScheduleLabel;
88
use crate::system::Resource;
99
use crate::world::World;
1010

@@ -20,8 +20,6 @@ pub use bevy_ecs_macros::States;
2020
///
2121
/// State transitions typically occur in the [`OnEnter<T::Variant>`] and [`OnExit<T:Variant>`] schedules,
2222
/// which can be run via the [`apply_state_transition::<T>`] system.
23-
/// Systems that run each frame in various states are typically stored in the main schedule,
24-
/// and are conventionally part of the [`OnUpdate(T::Variant)`] system set.
2523
///
2624
/// # Example
2725
///
@@ -66,14 +64,6 @@ pub struct OnTransition<S: States> {
6664
pub to: S,
6765
}
6866

69-
/// A [`SystemSet`] that will run within `CoreSet::Update` when this state is active.
70-
///
71-
/// This set, when created via `App::add_state`, is configured with a run condition.
72-
/// If all you want is the run condition, use the [`in_state`](crate::schedule::common_conditions::in_state)
73-
/// [condition](super::Condition) directly.
74-
#[derive(SystemSet, Clone, Debug, PartialEq, Eq, Hash)]
75-
pub struct OnUpdate<S: States>(pub S);
76-
7767
/// A finite-state machine whose transitions have associated schedules
7868
/// ([`OnEnter(state)`] and [`OnExit(state)`]).
7969
///

examples/2d/texture_atlas.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ fn main() {
99
.add_plugins(DefaultPlugins.set(ImagePlugin::default_nearest())) // prevents blurry sprites
1010
.add_state::<AppState>()
1111
.add_systems(OnEnter(AppState::Setup), load_textures)
12-
.add_systems(Update, check_textures.in_set(OnUpdate(AppState::Setup)))
12+
.add_systems(Update, check_textures.run_if(in_state(AppState::Setup)))
1313
.add_systems(OnEnter(AppState::Finished), setup)
1414
.run();
1515
}

examples/ecs/generic_system.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ fn main() {
3939
Update,
4040
(
4141
print_text_system,
42-
transition_to_in_game_system.in_set(OnUpdate(AppState::MainMenu)),
42+
transition_to_in_game_system.run_if(in_state(AppState::MainMenu)),
4343
),
4444
)
4545
// Cleanup systems.

examples/ecs/state.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ fn main() {
1818
.add_systems(OnEnter(AppState::Menu), setup_menu)
1919
// By contrast, update systems are stored in the `Update` schedule. They simply
2020
// check the value of the `State<T>` resource to see if they should run each frame.
21-
.add_systems(Update, menu.in_set(OnUpdate(AppState::Menu)))
21+
.add_systems(Update, menu.run_if(in_state(AppState::Menu)))
2222
.add_systems(OnExit(AppState::Menu), cleanup_menu)
2323
.add_systems(OnEnter(AppState::InGame), setup_game)
2424
.add_systems(
2525
Update,
26-
(movement, change_color).in_set(OnUpdate(AppState::InGame)),
26+
(movement, change_color).run_if(in_state(AppState::InGame)),
2727
)
2828
.run();
2929
}

examples/games/alien_cake_addict.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ fn main() {
3535
scoreboard_system,
3636
spawn_bonus,
3737
)
38-
.in_set(OnUpdate(GameState::Playing)),
38+
.run_if(in_state(GameState::Playing)),
3939
)
4040
.add_systems(OnExit(GameState::Playing), teardown)
4141
.add_systems(OnEnter(GameState::GameOver), display_score)
4242
.add_systems(
4343
Update,
4444
(
45-
gameover_keyboard.in_set(OnUpdate(GameState::GameOver)),
45+
gameover_keyboard.run_if(in_state(GameState::GameOver)),
4646
bevy::window::close_on_esc,
4747
),
4848
)

examples/games/game_menu.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ mod splash {
6262
// When entering the state, spawn everything needed for this screen
6363
.add_systems(OnEnter(GameState::Splash), splash_setup)
6464
// While in this state, run the `countdown` system
65-
.add_systems(Update, countdown.in_set(OnUpdate(GameState::Splash)))
65+
.add_systems(Update, countdown.run_if(in_state(GameState::Splash)))
6666
// When exiting the state, despawn everything that was spawned for this screen
6767
.add_systems(OnExit(GameState::Splash), despawn_screen::<OnSplashScreen>);
6868
}
@@ -131,7 +131,7 @@ mod game {
131131
impl Plugin for GamePlugin {
132132
fn build(&self, app: &mut App) {
133133
app.add_systems(OnEnter(GameState::Game), game_setup)
134-
.add_systems(Update, game.in_set(OnUpdate(GameState::Game)))
134+
.add_systems(Update, game.run_if(in_state(GameState::Game)))
135135
.add_systems(OnExit(GameState::Game), despawn_screen::<OnGameScreen>);
136136
}
137137
}
@@ -284,7 +284,7 @@ mod menu {
284284
Update,
285285
(
286286
setting_button::<DisplayQuality>
287-
.in_set(OnUpdate(MenuState::SettingsDisplay)),
287+
.run_if(in_state(MenuState::SettingsDisplay)),
288288
),
289289
)
290290
.add_systems(
@@ -295,7 +295,7 @@ mod menu {
295295
.add_systems(OnEnter(MenuState::SettingsSound), sound_settings_menu_setup)
296296
.add_systems(
297297
Update,
298-
setting_button::<Volume>.in_set(OnUpdate(MenuState::SettingsSound)),
298+
setting_button::<Volume>.run_if(in_state(MenuState::SettingsSound)),
299299
)
300300
.add_systems(
301301
OnExit(MenuState::SettingsSound),
@@ -304,7 +304,7 @@ mod menu {
304304
// Common systems to all screens that handles buttons behaviour
305305
.add_systems(
306306
Update,
307-
(menu_action, button_system).in_set(OnUpdate(GameState::Menu)),
307+
(menu_action, button_system).run_if(in_state(GameState::Menu)),
308308
);
309309
}
310310
}

0 commit comments

Comments
 (0)