bevy
bevy copied to clipboard
SystemParamBuilder - Support dynamic system parameters
Objective
Support building systems with parameters whose types can be determined at runtime.
Solution
Create a DynSystemParam type that can be built using a SystemParamBuilder of any type and then downcast to the appropriate type dynamically.
Example
let system = (
DynParamBuilder::new(LocalBuilder(3_usize)),
DynParamBuilder::new::<Query<()>>(QueryParamBuilder::new(|builder| {
builder.with::<A>();
})),
DynParamBuilder::new::<&Entities>(ParamBuilder),
)
.build_state(&mut world)
.build_system(
|mut p0: DynSystemParam, mut p1: DynSystemParam, mut p2: DynSystemParam| {
let local = p0.downcast_mut::<Local<usize>>().unwrap();
let query_count = p1.downcast_mut::<Query<()>>().unwrap();
let entities = p2.downcast_mut::<&Entities>().unwrap();
},
);