Skip to content

Commit 4b317e6

Browse files
committed
Wrote some documentation on query filters - noting how they interact with system ordering
1 parent ab407aa commit 4b317e6

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

crates/bevy_ecs/src/query/filter.rs

+56
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,30 @@ macro_rules! impl_flag_filter {
574574

575575
impl_flag_filter!(
576576
/// Filter that retrieves components of type `T` that have been added since the start of the frame
577+
///
578+
/// This filter is useful as a performance optimization as it means that a system can be made to run only when
579+
/// it needs to rather than every frame.
580+
///
581+
/// Because the ordering of systems can change and this filter is only effective on changes before the query executes
582+
/// you need to use explicit dependency ordering or ordered stages for these query filters to be useful.
583+
///
584+
///
585+
/// Example:
586+
/// ```
587+
/// # use bevy_ecs::system::Query;
588+
/// # use bevy_ecs::query::Added;
589+
/// #
590+
/// # #[derive(Debug)]
591+
/// # struct Name {};
592+
/// # struct Transform {};
593+
/// #
594+
/// fn print_add_name_component(query: Query<&Name, Added<Name>>) {
595+
/// for name in query.iter() {
596+
/// println!("Named entity created: {:?}", name)
597+
/// }
598+
/// }
599+
/// ```
600+
577601
Added,
578602
AddedState,
579603
AddedFetch,
@@ -583,6 +607,29 @@ impl_flag_filter!(
583607
impl_flag_filter!(
584608
/// Filter that retrieves components of type `T` that have been mutated since the start of the frame.
585609
/// Added components do not count as mutated.
610+
///
611+
/// This filter is useful as a performance optimization as it means that a system can be made to run only when
612+
/// it needs to rather than every frame.
613+
///
614+
/// Because the ordering of systems can change and this filter is only effective on changes before the query executes
615+
/// you need to use explicit dependency ordering or ordered stages for these query filters to be useful.
616+
///
617+
/// Example:
618+
/// ```
619+
/// # use bevy_ecs::system::Query;
620+
/// # use bevy_ecs::query::Mutated;
621+
/// #
622+
/// # #[derive(Debug)]
623+
/// # struct Name {};
624+
/// # struct Transform {};
625+
/// #
626+
/// fn print_moving_objects_system(query: Query<&Name, Mutated<Transform>>) {
627+
/// for name in query.iter() {
628+
/// println!("Entity Moved: {:?}", name)
629+
/// }
630+
/// }
631+
/// ```
632+
586633
Mutated,
587634
MutatedState,
588635
MutatedFetch,
@@ -591,6 +638,15 @@ impl_flag_filter!(
591638

592639
impl_flag_filter!(
593640
/// Filter that retrieves components of type `T` that have been added or mutated since the start of the frame
641+
///
642+
/// This filter is useful as a performance optimization as it means that a system can be made to run only when
643+
/// it needs to rather than every frame.
644+
///
645+
/// Because the ordering of systems can change and this filter is only effective on changes before the query executes
646+
/// you need to use explicit dependency ordering or ordered stages for these query filters to be useful.
647+
///
648+
/// Also see the documentation for [`Mutated<T>`] and [`Added`] as this filter is a logical OR of them.
649+
594650
Changed,
595651
ChangedState,
596652
ChangedFetch,

0 commit comments

Comments
 (0)