Skip to content

Commit

Permalink
fix: change detection example
Browse files Browse the repository at this point in the history
  • Loading branch information
BD103 committed Jul 27, 2024
1 parent 0dba2c7 commit 2751878
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions examples/ecs/component_change_detection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,25 @@ fn change_component(time: Res<Time>, mut query: Query<(Entity, &mut MyComponent)
// Only entities matching the filters will be in the query
fn change_detection(query: Query<(Entity, Ref<MyComponent>), Changed<MyComponent>>) {
for (entity, component) in &query {
// By default you can only what component was changed on each entity. This is useful, but
// what if you have multiple systems modifying the same component?
#[cfg(not(feature = "track_change_detection"))]
info!(
"{:?} changed: {:?} by: {}",
"{:?} changed {:?}",
entity,
component,
component.changed_by()
);

// If you enable the `track_change_detection` feature, you can unlock the
// `Ref::changed_by()` method. It returns the `Location`, the file and line number, that
// the component was changed in. It's not recommended for released games, but great for
// debugging!
#[cfg(feature = "track_change_detection")]
info!(
"{:?} changed {:?} in {}",
entity,
component,
component.changed_by(),
);
}
}
Expand Down

0 comments on commit 2751878

Please sign in to comment.