我使用 bevy 0.6 和 rapierphysics_2d 0.12.0 由于清除场景而感到恐慌。我有以下两个功能::
fn cleanup_player(mut commands: Commands, player_data: Res<PlayerData>, query: Query<Entity>) {
commands
.entity(player_data.player_entity)
.despawn_recursive();
commands
.entity(player_data.camera_entity)
.despawn_recursive();
}
fn cleanup(mut commands: Commands, query: Query<Entity>) {
for entity in query.iter() {
commands.entity(entity).despawn_recursive();
}
}
如您所见,它们只是消失创建的较早实体。但是,如果我使用其中的任何一个,它都会引起恐慌。
我实际上是在尝试从 InGame 更改为 MainMenu 时调用它们(通过按 ESC)
impl Plugin for PugPlugin {
fn build(&self, app: &mut App) {
app.add_plugin(RapierPhysicsPlugin::<NoUserData>::default())
.add_system(camera_follow_player.label("Camera system"))
.add_system_set(
SystemSet::on_enter(crate::AppState::InGame)
.with_system(sprite_spawn)
.with_system(spawn_floor),
)
.add_system_set(
SystemSet::on_update(crate::AppState::InGame)
.with_system(check_delete)
.with_system(myphysics::player_jumps.label("Player Jumps System"))
.with_system(myphysics::jump_reset.label("Jump Reset System"))
.with_system(myphysics::player_movement.label("Player Movement System"))
.with_system(death_by_height.label("Death system"))
,
)
.add_system_set(SystemSet::on_exit(AppState::InGame).with_system(cleanup).with_system(cleanup_player))
;
}
}
最后可以看到系统设置。所以我想从 InGame Set 切换到主菜单,它不起作用。
即使没有到 MainMenu 或 smth 的任何转换,ps just clean 功能也无法在场景中工作。所以我什至不能从我的游戏中删除任何实体。
thread 'Compute Task Pool (0)' panicked at 'Attempting to create an EntityCommands for entity 1v1, which doesn't exist.', /Users/Alexander/.cargo/registry/src/github.com-1ecc6299db9ec823/bevy_rapier2d-0.12.0/src/physics/resources.rs:240:26