Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Jondolf opened this issue May 9, 2024 · 0 comments
Labels
A-Integration very bevy specific D-Easy P-Medium S-not-started Work has not started

Comments

@Jondolf
Copy link

Jondolf commented May 9, 2024

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.

@Jondolf Jondolf changed the title IntegrationParameters is inconvenient to configure at start-up due to private fields on RapierContext IntegrationParameters is inconvenient to configure at startup due to private fields on RapierContext May 9, 2024
@Vrixyz Vrixyz added D-Easy P-Medium S-not-started Work has not started A-Integration very bevy specific labels May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Integration very bevy specific D-Easy P-Medium S-not-started Work has not started
Projects
None yet
Development

No branches or pull requests

2 participants