Hi, I'm trying to understand why a .clone() on an entity with a Collider would cause a game to freeze.
Simple example:
use avian2d::prelude::*; // 0.4.1
use bevy::prelude::*; // 0.17.2
#[derive(Component, Clone)]
struct NeedDup;
fn main() {
App::new()
.add_plugins((DefaultPlugins, PhysicsPlugins::default()))
.add_systems(Startup, |mut cmds: Commands| {
cmds.spawn(Camera2d);
})
.add_systems(Update, spawn)
.add_systems(Update, dup)
.run();
}
fn spawn(mut cmds: Commands, mut mt: ResMut<Assets<ColorMaterial>>, mut ms: ResMut<Assets<Mesh>>) {
cmds.spawn((
NeedDup,
RigidBody::Dynamic,
Collider::circle(2.0),
MeshMaterial2d(mt.add(ColorMaterial::from_color(Color::WHITE))),
Mesh2d(ms.add(Circle::new(2.0))),
));
}
fn dup(mut cmds: Commands, entities: Query<Entity, With<NeedDup>>) {
entities.iter().for_each(|entity| {
cmds.entity(entity).remove::<NeedDup>().clone_and_spawn();
});
}
Note that:
- I've reduced the example as much as possible, the crash happens even without
Camera2d,MeshMaterial2d, orMesh2d, it's left here for visual purpose. clone_and_spawnmany entities withoutColliderworks.cmd.spawn(...)many times withColliderworks.- I've already opened https://github.com/avianphysics/avian/issues/880 as this looks like a bug, but I'm curious for other feedback as well.
Any ideas of what I am doing wrong, or if this is a bug?