-
-
Notifications
You must be signed in to change notification settings - Fork 273
Description
I was trying to configure the number of solver iterations, which reside in IntegrationParameters, stored in the RapierContext resource. Like how most resources in Bevy are typically configured at start-up, I tried inserting the resource:
fn main() {
App::new()
.add_plugins((DefaultPlugins, RapierPhysicsPlugin::<()>::default()))
.insert_resource(RapierContext {
integration_parameters: IntegrationParameters {
num_solver_iterations: NonZeroUsize::new(6).unwrap(),
..default()
},
..default() // error: "field `event_handler` of struct `bevy_rapier2d::plugin::RapierContext` is private" and so on
})
.run();
}The property spread operation fails, because there are several private fields. There also doesn't seem to be a way to configure the integration parameters directly through a constructor or builder method.
Instead, an intermediary variable needs to be created for the RapierContext.
fn main() {
let mut ctx = RapierContext::default();
ctx.integration_parameters = IntegrationParameters {
num_solver_iterations: NonZeroUsize::new(6).unwrap(),
..default()
};
App::new()
.add_plugins((DefaultPlugins, RapierPhysicsPlugin::<()>::default()))
.insert_resource(ctx)
.run();
}This isn't immediately obvious, and it's different from how resources are typically configured.
Compare this to changing the substep count in e.g. bevy_xpbd:
fn main() {
App::new()
.add_plugins((DefaultPlugins, PhysicsPlugins::default()))
.insert_resource(SubstepCount(6))
.run();
}Either the fields on RapierContext should be made public, or (preferably) the IntegrationParameters should be extracted into their own resource.