dimforge / dimforge/bevy_rapier

`IntegrationParameters` is inconvenient to configure at startup due to private fields on `RapierContext`

Open
#503 0 comments 0 reactions 0 assignees View on GitHub
A-Integration C-Enhancement D-Easy P-Medium S-not-started
Dominant language
Rust
Stars
1.6k
Forks
282
PR merge metrics
No merged PRs in 30d

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:

```rust
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`.

```rust
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:

```rust
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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.