-
It is not exactly a stopping issue, so I am asking it here under discussions>Q&A. Need some help to clarify optimum method to despawn, which is related to a previously closed issue (#43). bevy_proto/examples/custom_schematic.rs Line 85 in 37a72d7 In the line 85 as per excerpt above, it is noted that we need to define a dedicated way to de-spawn & remove the entity. I tried to use the following but received an error: // fn remove in impl Schematic for Cardset
fn remove(_input: &Self::Input, context: &mut SchematicContext) {
dbg!("test");
let world = context.world_mut();
let mut query = world.query_filtered::<Entity, With<Cardset>>();
let entity_vec = query.iter(world).collect::<Vec<Entity>>();
for entity in entity_vec {
world.despawn(entity);
}
context.entity_mut().unwrap().remove::<NodeBundle>();
}
// despawn code
fn despawn(
mut commands: Commands,
mut proto_commands: ProtoEntityCommands, //tried adding this line 1
query: Query<Entity, With<CardsetRoot>,
mut is_spawned: ResMut<IsCardsetRootSpawned>,
) {
if let Ok(entity) = query.get_single() {
proto_commands.remove(PROTO_ID); //tried adding this line 2
commands.entity(entity).despawn_recursive();
is_spawned.value = false;
}
}
// error
the trait bound `for<'a, 'b, 'c, 'd, 'e, 'f, 'g, 'h> fn(bevy::prelude::Commands<'a, 'b>, bevy_proto::backend::proto::ProtoEntityCommands<'c, 'd, 'e, Prototype, ProtoConfig>, bevy::prelude::Query<'f, 'g, bevy::prelude::Entity, bevy::prelude::With<CardsetRoot>>, bevy::prelude::ResMut<'h, IsCardsetRootSpawned>) {game::card::cardset::despawn}: bevy::prelude::IntoSystem<(), (), _>` is not satisfied |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Found out that I forget to include one line into the It is now behaving as expected across different implementation. At the same time, still curious on the best/optimum way to do de-spawning if there is any. |
Beta Was this translation helpful? Give feedback.
Hi @hafiidz, really sorry for being so late to respond to this (got some life stuff going on lol).
The
remove
functionality is mainly meant for two scenarios:The example is demonstrating scenario 2: the
apply
method spawned in some camera entities that were not children of the prototype entity and so when weremove
that prototype, we want to "undo" that world mutation by despawning those cameras.If all schematics in your prototype are just components/bundles, with no other special
Schematic
implementations, then I would just opt for the normalcommands.despawn
. Otherwise, l…