diff --git a/crates/bevy_ecs/src/query/state.rs b/crates/bevy_ecs/src/query/state.rs index 87ea0854dfded..16a0ea6c9d3a0 100644 --- a/crates/bevy_ecs/src/query/state.rs +++ b/crates/bevy_ecs/src/query/state.rs @@ -652,6 +652,41 @@ impl QueryState { } } + /// Returns an [`Iterator`] over the read-only query items generated from an [`Entity`] list. + /// + /// Items are returned in the order of the list of entities. + /// Entities that don't match the query are skipped. + /// + /// If `world` archetypes changed since [`Self::update_archetypes`] was last called, + /// this will skip entities contained in new archetypes. + /// + /// This can only be called for read-only queries. + /// + /// # See also + /// + /// - [`iter_many`](Self::iter_many) to update archetypes. + /// - [`iter_manual`](Self::iter_manual) to iterate over all query items. + #[inline] + pub fn iter_many_manual<'w, 's, EntityList: IntoIterator>( + &'s self, + world: &'w World, + entities: EntityList, + ) -> QueryManyIter<'w, 's, Q::ReadOnly, F::ReadOnly, EntityList::IntoIter> + where + EntityList::Item: Borrow, + { + self.validate_world(world); + // SAFETY: query is read only, world id is validated + unsafe { + self.as_readonly().iter_many_unchecked_manual( + entities, + world, + world.last_change_tick(), + world.read_change_tick(), + ) + } + } + /// Returns an iterator over the query items generated from an [`Entity`] list. /// /// Items are returned in the order of the list of entities.