Skip to content

Commit 05d4c51

Browse files
mockersfbeicause
authored andcommitted
do not require bevy_dev_tools for states example (bevyengine#19364)
# Objective - Example `states` require the `bevy_dev_tools` feature even though its not needed for states ## Solution - Make the `bevy_dev_tools` feature optional, and explain why it can be used
1 parent 4716d5f commit 05d4c51

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2400,7 +2400,6 @@ wasm = false
24002400
name = "states"
24012401
path = "examples/state/states.rs"
24022402
doc-scrape-examples = true
2403-
required-features = ["bevy_dev_tools"]
24042403

24052404
[package.metadata.example.states]
24062405
name = "States"

examples/state/states.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
//!
66
//! In this case, we're transitioning from a `Menu` state to an `InGame` state.
77
8-
use bevy::{dev_tools::states::*, prelude::*};
8+
use bevy::prelude::*;
99

1010
fn main() {
11-
App::new()
12-
.add_plugins(DefaultPlugins)
11+
let mut app = App::new();
12+
app.add_plugins(DefaultPlugins)
1313
.init_state::<AppState>() // Alternatively we could use .insert_state(AppState::Menu)
1414
.add_systems(Startup, setup)
1515
// This system runs when we enter `AppState::Menu`, during the `StateTransition` schedule.
@@ -24,9 +24,14 @@ fn main() {
2424
.add_systems(
2525
Update,
2626
(movement, change_color).run_if(in_state(AppState::InGame)),
27-
)
28-
.add_systems(Update, log_transitions::<AppState>)
29-
.run();
27+
);
28+
29+
#[cfg(feature = "bevy_dev_tools")]
30+
app.add_systems(Update, bevy::dev_tools::states::log_transitions::<AppState>);
31+
#[cfg(not(feature = "bevy_dev_tools"))]
32+
warn!("Enable feature bevy_dev_tools to log state transitions");
33+
34+
app.run();
3035
}
3136

3237
#[derive(Debug, Clone, Copy, Default, Eq, PartialEq, Hash, States)]

0 commit comments

Comments
 (0)