Skip to content

Commit 9984bbe

Browse files
authored
Try #3084:
2 parents 3431335 + cdf4bf0 commit 9984bbe

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

crates/bevy_ecs/src/query/filter.rs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -630,18 +630,28 @@ impl_tick_filter!(
630630
);
631631

632632
impl_tick_filter!(
633-
/// Filter that retrieves components of type `T` that have been changed since the last
634-
/// execution of this system.
633+
/// Filter that retrieves components of type `T` that have been changed since the last tick.
635634
///
636-
/// This filter is useful for synchronizing components, and as a performance optimization as it
637-
/// means that the query contains fewer items for a system to iterate over.
635+
/// All components internally remember the last tick they were added at, and the last tick they
636+
/// were mutated at. The mutation detection is powered by [`DerefMut`](std::ops::DerefMut), such that any mutable dereferencing
637+
/// will mark the component as changed. Note that there is no deep value inspection on the actual
638+
/// data of the component, which would be prohibitively expensive. This means false positives can
639+
/// occur if dereferencing via [`DerefMut`](std::ops::DerefMut) but not changing any component data.
640+
/// Just reading the value of a component will not mark it as changed, as [`Deref`](std::ops::Deref) will be used instead.
638641
///
639-
/// Because the ordering of systems can change and this filter is only effective on changes
640-
/// before the query executes you need to use explicit dependency ordering or ordered
641-
/// stages to avoid frame delays.
642+
/// This filter is useful for synchronizing components. It can also be used as a performance
643+
/// optimization in case of expensive operations, by filtering unchanged components out and
644+
/// returning via the query only the components which changed. However, note that like all
645+
/// filterings, applying this filtering has a small cost, which must be balanced against the
646+
/// cost of the operation on the changed components.
642647
///
643-
/// If instead behavior is meant to change on whether the component changed or not
644-
/// [`ChangeTrackers`](crate::query::ChangeTrackers) may be used.
648+
/// Because by default the ordering of systems within the same stage is nondeterministic, and this filter is only effective
649+
/// on changes detected before the query executes, to avoid frame delays you need to use
650+
/// explicit dependency ordering or ordered stages to ensure the detecting system where the
651+
/// query is used runs after the system(s) which mutate the component.
652+
///
653+
/// To instead retrieve all components without filtering but allow querying if they changed
654+
/// or not since last tick, you can use [`ChangeTrackers`](crate::query::ChangeTrackers).
645655
///
646656
/// # Examples
647657
///

0 commit comments

Comments
 (0)