dimforge / bevy_rapier

Official Rapier plugin for the Bevy game engine.
https://rapier.rs
Apache License 2.0
1.22k stars 259 forks source link

Panic when using Bevy parenting #76

Closed ksev closed 3 years ago

ksev commented 3 years ago

I tried to bevy_rapier 0.10 into my game project. But i was met with some issues namely this panic that occurs when you add a ColliderBundle to an entity that has a parent (in the Bevy sense).

Example code that exhibits the crash, adapted from one of your examples:

use bevy::prelude::*;
use bevy_rapier3d::prelude::*;

use rapier3d::pipeline::PhysicsPipeline;

fn main() {
    App::build()
        .add_plugins(DefaultPlugins)
        .add_plugin(bevy_winit::WinitPlugin::default())
        .add_plugin(bevy_wgpu::WgpuPlugin::default())
        .add_plugin(RapierPhysicsPlugin::<NoUserData>::default())
        .add_startup_system(setup_physics.system())
        .run();
}

pub fn setup_physics(mut commands: Commands) {
    let parent = commands
        .spawn_bundle((Transform::identity(), GlobalTransform::identity()))
        .id();

    let collider = ColliderBundle {
        shape: ColliderShape::cuboid(4.0, 1.2, 1.2),
        ..ColliderBundle::default()
    };

    commands
        .spawn_bundle(collider)
        // This next line is the offending code, uncomment and it works
        .insert(Parent(parent))
        .insert(ColliderDebugRender::default())
        .insert(ColliderPositionSync::Discrete);
}
ksev commented 3 years ago

Oh and i forgot this is the error:

thread 'Compute Task Pool (23)' panicked at 'called Option::unwrap() on a None value', C:\\build\rapier3d../../src\data\component_set.rs:27:26