Skip to content

[Merged by Bors] - Added documentation on the query filters #1553

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
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions crates/bevy_ecs/src/query/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,29 @@ macro_rules! impl_flag_filter {

impl_flag_filter!(
/// Filter that retrieves components of type `T` that have been added since the start of the frame
///
/// This filter is useful as a performance optimization as it means that the query contains fewer items
/// for a system to iterate over.
///
/// Because the ordering of systems can change and this filter is only effective on changes before the query executes
/// you need to use explicit dependency ordering or ordered stages for these query filters to be useful.
///
///
/// Example:
/// ```
/// # use bevy_ecs::system::Query;
/// # use bevy_ecs::query::Added;
/// #
/// # #[derive(Debug)]
/// # struct Name {};
/// # struct Transform {};
/// #
/// fn print_add_name_component(query: Query<&Name, Added<Name>>) {
/// for name in query.iter() {
/// println!("Named entity created: {:?}", name)
/// }
/// }
/// ```
Added,
AddedState,
AddedFetch,
Expand All @@ -583,6 +606,28 @@ impl_flag_filter!(
impl_flag_filter!(
/// Filter that retrieves components of type `T` that have been mutated since the start of the frame.
/// Added components do not count as mutated.
///
/// This filter is useful as a performance optimization as it means that the query contains fewer items
/// for a system to iterate over.
///
/// Because the ordering of systems can change and this filter is only effective on changes before the query executes
/// you need to use explicit dependency ordering or ordered stages for these query filters to be useful.
///
/// Example:
/// ```
/// # use bevy_ecs::system::Query;
/// # use bevy_ecs::query::Mutated;
/// #
/// # #[derive(Debug)]
/// # struct Name {};
/// # struct Transform {};
/// #
/// fn print_moving_objects_system(query: Query<&Name, Mutated<Transform>>) {
/// for name in query.iter() {
/// println!("Entity Moved: {:?}", name)
/// }
/// }
/// ```
Mutated,
MutatedState,
MutatedFetch,
Expand All @@ -591,6 +636,14 @@ impl_flag_filter!(

impl_flag_filter!(
/// Filter that retrieves components of type `T` that have been added or mutated since the start of the frame
///
/// This filter is useful as a performance optimization as it means that the query contains fewer items
/// for a system to iterate over.
///
/// Because the ordering of systems can change and this filter is only effective on changes before the query executes
/// you need to use explicit dependency ordering or ordered stages for these query filters to be useful.
///
/// Also see the documentation for [`Mutated<T>`] and [`Added`] as this filter is a logical OR of them.
Changed,
ChangedState,
ChangedFetch,
Expand Down