-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Improve bevy_ecs inspectability and add debugging methods.
#17331
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
AlephCubed
wants to merge
30
commits into
bevyengine:main
from
AlephCubed:ecs-inspectability-adopted-conflict
Closed
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
eca5de6
Add len, iter on Bundles, add an example to show how to inspect a world
shuoli84 cb8f377
Add schedule diagnostic example
shuoli84 47f0860
fix clippy, remove unused code
shuoli84 f951e57
add a note explain why need a special label
shuoli84 4505730
clippy
shuoli84 a16f720
fix index mismatch between graph and executor. return a string repr f…
shuoli84 81802d7
fix clippy. add more details in diagnostic
shuoli84 81d22ed
fix clippy
shuoli84 bddb539
Merge branch 'main' into ecs-inspectability-adopted-conflict
AlephCubed 54b046c
Fixed CI not passing.
AlephCubed 14578c1
Updated schedule label code in example.
AlephCubed dc34cd4
Merge branch 'bevyengine:main' into ecs-inspectability-adopted-conflict
AlephCubed 8619f8b
Fix spelling mistakes + format.
AlephCubed d14d70a
Replaced `component_display` with `ComponentId::diagnose`.
AlephCubed 5a9b6a7
Replaced `diagnose_dag` with `Dag::diagnose`.
AlephCubed 9d5bb88
Replaced `diagnostic_schedules` with `Schedules::diagnose`.
AlephCubed 51b3098
Replaced `diagnostic_world` with `World::diagnose`.
AlephCubed 159e607
Added `Systems::diagnose_flattened`.
AlephCubed a852d28
Added `World::diagnose_with_flattened`.
AlephCubed d891ef5
Replaced `"".to_string()` with `String::new()`.
AlephCubed 84e29f1
Merge remote-tracking branch 'upstream/main' into ecs-inspectability-…
AlephCubed 80e5e11
Merge branch 'ecs-inspectability-adopted-conflict' into diagnose-flat…
AlephCubed 4f70216
Fix CI not passing due to new requirements.
AlephCubed 3ae2ae7
Merge branch 'ecs-inspectability-adopted-conflict' into diagnose-flat…
AlephCubed 9177b0f
Final Cleanup.
AlephCubed fa75f6f
Merge remote-tracking branch 'upstream/main' into ecs-inspectability-…
AlephCubed cb6611b
Added more documentation and comments to example.
AlephCubed 644ab19
Update doc comment for `Dag::diagnose`.
AlephCubed 03e0276
Made `Schedule::systems_for_each` private.
AlephCubed cdb53b3
Merge remote-tracking branch 'upstream/main' into ecs-inspectability-…
AlephCubed File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| //! In this example, we use a system to print diagnostic information about the world. | ||
| //! | ||
| //! This includes information about which components, bundles, and systems are registered, | ||
| //! as well as the order that systems will run in. | ||
|
|
||
| #![expect( | ||
| missing_docs, | ||
| reason = "Trivial example types do not require documentation." | ||
| )] | ||
|
|
||
| use bevy_ecs::prelude::*; | ||
| use bevy_ecs_macros::{ScheduleLabel, SystemSet}; | ||
|
|
||
| fn empty_system() {} | ||
|
|
||
| fn first_system() {} | ||
|
|
||
| fn second_system() {} | ||
|
|
||
| fn increase_game_state_count(mut state: ResMut<GameState>) { | ||
| state.counter += 1; | ||
| } | ||
|
|
||
| fn sync_counter(state: Res<GameState>, mut query: Query<&mut Counter>) { | ||
| for mut counter in query.iter_mut() { | ||
| counter.0 = state.counter; | ||
| } | ||
| } | ||
|
|
||
| #[derive(Resource, Default)] | ||
| struct GameState { | ||
| counter: usize, | ||
| } | ||
|
|
||
| #[derive(SystemSet, Hash, Clone, Copy, PartialEq, Eq, Debug)] | ||
| enum MySet { | ||
| Set1, | ||
| Set2, | ||
| } | ||
|
|
||
| #[derive(Component)] | ||
| struct Counter(usize); | ||
|
|
||
| #[derive(Component)] | ||
| struct Player; | ||
|
|
||
| #[derive(Component)] | ||
| #[component(storage = "SparseSet")] | ||
| struct HighlightFlag; | ||
|
|
||
| #[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)] | ||
| pub enum ScheduleLabel { | ||
| Foo, | ||
| Bar, | ||
| } | ||
|
|
||
| /// A special label for diagnostic. | ||
| /// If a system has a commonly used label, like [`bevy_app::CoreSchedule`] it is not able to get | ||
| /// the corresponding [`Schedule`] instance and can't be inspected. | ||
| #[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)] | ||
| pub struct DiagnosticLabel; | ||
|
|
||
| /// World diagnostic example. | ||
| fn diagnostic_world_system(world: &mut World) { | ||
| println!("{}", world.diagnose_with_flattened().unwrap()); | ||
| } | ||
|
|
||
| // If you do not have mutable access, you can also use [`World::diagnose`]. | ||
| // This version will not include a flattened representation. | ||
| // | ||
| // fn diagnostic_world_system(world: &World) { | ||
| // println!("{}", world.diagnose().unwrap()); | ||
| // } | ||
|
|
||
| // In this example, we add a counter resource and increase its value in one system, | ||
| // while a different system prints debug information about the world. | ||
| fn main() { | ||
| let mut world = World::new(); | ||
| world.init_resource::<Schedules>(); | ||
|
|
||
| { | ||
| let mut diagnostic_schedule = Schedule::new(DiagnosticLabel); | ||
| diagnostic_schedule.add_systems(diagnostic_world_system); | ||
| world.add_schedule(diagnostic_schedule); | ||
| } | ||
|
|
||
| let mut schedule = Schedule::new(ScheduleLabel::Bar); | ||
| schedule.configure_sets((MySet::Set1, MySet::Set2)); | ||
|
|
||
| schedule.add_systems(empty_system.in_set(MySet::Set1)); | ||
| schedule.add_systems( | ||
| increase_game_state_count | ||
| .in_set(MySet::Set1) | ||
| .before(sync_counter), | ||
| ); | ||
| schedule.add_systems(sync_counter); | ||
| schedule.add_systems(first_system.before(second_system).in_set(MySet::Set2)); | ||
| schedule.add_systems(second_system.in_set(MySet::Set2)); | ||
| world.add_schedule(schedule); | ||
|
|
||
| world.init_resource::<GameState>(); | ||
|
|
||
| world.run_schedule(ScheduleLabel::Bar); | ||
| world.run_schedule(DiagnosticLabel); | ||
|
|
||
| let player = world.spawn(Player).id(); | ||
| // Create an archetype with one table component and one sparse set. | ||
| world.spawn((Counter(1), HighlightFlag)); | ||
| world.run_schedule(ScheduleLabel::Bar); | ||
| world.run_schedule(DiagnosticLabel); | ||
|
|
||
| world.entity_mut(player).insert(Counter(100)); | ||
| world.run_schedule(ScheduleLabel::Bar); | ||
| world.run_schedule(DiagnosticLabel); | ||
|
|
||
| world.entity_mut(player).insert(HighlightFlag); | ||
| world.run_schedule(ScheduleLabel::Bar); | ||
| world.run_schedule(DiagnosticLabel); | ||
|
|
||
| world.entity_mut(player).despawn(); | ||
| world.run_schedule(ScheduleLabel::Bar); | ||
| world.run_schedule(DiagnosticLabel); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be good to elaborate more on this. For example, what diagnostic info do we get and why is this useful to see?