diff --git a/crates/bevy_ecs/src/system/builder.rs b/crates/bevy_ecs/src/system/builder.rs index 520d73f4e9..2cecceeb3c 100644 --- a/crates/bevy_ecs/src/system/builder.rs +++ b/crates/bevy_ecs/src/system/builder.rs @@ -212,7 +212,7 @@ all_tuples!(impl_system_param_builder_tuple, 0, 16, P, B); /// A [`SystemParamBuilder`] for a [`ParamSet`]. /// To build a [`ParamSet`] with a tuple of system parameters, pass a tuple of matching [`SystemParamBuilder`]s. /// To build a [`ParamSet`] with a `Vec` of system parameters, pass a `Vec` of matching [`SystemParamBuilder`]s. -pub struct ParamSetBuilder(T); +pub struct ParamSetBuilder(pub T); macro_rules! impl_param_set_builder_tuple { ($(($param: ident, $builder: ident, $meta: ident)),*) => { diff --git a/crates/bevy_ecs/src/system/system_param.rs b/crates/bevy_ecs/src/system/system_param.rs index 3bf032590a..acc876a556 100644 --- a/crates/bevy_ecs/src/system/system_param.rs +++ b/crates/bevy_ecs/src/system/system_param.rs @@ -390,6 +390,46 @@ fn assert_component_access_compatibility( /// } /// # bevy_ecs::system::assert_is_system(event_system); /// ``` +/// +/// If you want to use `ParamSet` with a [`SystemParamBuilder`](crate::system::SystemParamBuilder), use [`ParamSetBuilder`](crate::system::ParamSetBuilder) and pass a builder for each param. +/// ``` +/// # use bevy_ecs::{prelude::*, system::*}; +/// # +/// # #[derive(Component)] +/// # struct Health; +/// # +/// # #[derive(Component)] +/// # struct Enemy; +/// # +/// # #[derive(Component)] +/// # struct Ally; +/// # +/// let mut world = World::new(); +/// +/// let system = (ParamSetBuilder(( +/// QueryParamBuilder::new(|builder| { +/// builder.with::(); +/// }), +/// QueryParamBuilder::new(|builder| { +/// builder.with::(); +/// }), +/// ParamBuilder, +/// )),) +/// .build_state(&mut world) +/// .build_system(buildable_system); +///world.run_system_once(system); +/// +/// fn buildable_system(mut set: ParamSet<(Query<&mut Health>, Query<&mut Health>, &World)>) { +/// // The first parameter is built from the first builder, +/// // so this will iterate over enemies. +/// for mut health in set.p0().iter_mut() {} +/// // And the second parameter is built from the second builder, +/// // so this will iterate over allies. +/// for mut health in set.p1().iter_mut() {} +/// // Parameters that don't need special building can use `ParamBuilder`. +/// let entities = set.p2().entities(); +/// } +/// ``` pub struct ParamSet<'w, 's, T: SystemParam> { param_states: &'s mut T::State, world: UnsafeWorldCell<'w>,