diff --git a/crates/bevy_ecs/src/query/state.rs b/crates/bevy_ecs/src/query/state.rs index f675de4d89a1d..796394031113a 100644 --- a/crates/bevy_ecs/src/query/state.rs +++ b/crates/bevy_ecs/src/query/state.rs @@ -2,6 +2,7 @@ use crate::{ archetype::{Archetype, ArchetypeComponentId, ArchetypeGeneration, ArchetypeId}, component::ComponentId, entity::Entity, + prelude::FromWorld, query::{ Access, Fetch, FetchState, FilterFetch, FilteredAccess, NopFetch, QueryCombinationIter, QueryIter, WorldQuery, @@ -32,6 +33,15 @@ where pub(crate) filter_state: F::State, } +impl FromWorld for QueryState +where + F::Fetch: FilterFetch, +{ + fn from_world(world: &mut World) -> Self { + world.query_filtered() + } +} + impl QueryState where F::Fetch: FilterFetch, diff --git a/crates/bevy_ecs/src/system/function_system.rs b/crates/bevy_ecs/src/system/function_system.rs index c03d09684f844..f3cade700fce5 100644 --- a/crates/bevy_ecs/src/system/function_system.rs +++ b/crates/bevy_ecs/src/system/function_system.rs @@ -1,6 +1,7 @@ use crate::{ archetype::{Archetype, ArchetypeComponentId, ArchetypeGeneration, ArchetypeId}, component::ComponentId, + prelude::FromWorld, query::{Access, FilteredAccessSet}, schedule::SystemLabel, system::{ @@ -229,6 +230,12 @@ impl SystemState { } } +impl FromWorld for SystemState { + fn from_world(world: &mut World) -> Self { + Self::new(world) + } +} + /// Conversion trait to turn something into a [`System`]. /// /// Use this to get a system from a function. Also note that every system implements this trait as