-
Hello, I am developing BEVY in a web environment. The following error occurred in the browser console while developing. After hours of identifying the problem without knowing what the problem was, we found that despawn entity in the web environment resulted in an error. Below is the code where the error occurred.. pub fn ui_sidebox_close(
mut commands: Commands,
query_sidebox_entity: Query<(Entity, &SideBox)>
//query: Query<Entity, With<SideBox>> //This also has an error
){
for (entity, sidebox) in query_sidebox_entity.iter() {
if sidebox.is_dead {
if sidebox.size <= 5.001 {
console::log_1(&JsValue::from_str("try kill the entity..."));
commands.entity(entity).despawn();
}
}
}
// for entity in query.iter(){
// commands.entity(entity).despawn(); //This also has an error
// }
} As far as I know, there is no problem with the above code in BEVY. However, I am not very sure because the relevant pages of informal documents are based on 0.9. How can we solve this problem? Thank you. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Looks some UI system doesn't handle child entities being despawned here: bevy/crates/bevy_ui/src/update.rs Lines 40 to 41 in 12c6fa7
|
Beta Was this translation helpful? Give feedback.
-
If devil-ira's advice may work as well, but it's likely that your The root problem is that |
Beta Was this translation helpful? Give feedback.
If
SideBox
exists in a hierarchy, you probably want to usedespawn_recursive
.devil-ira's advice may work as well, but it's likely that your
SideBar
has children that need to be despawned as well. If that's the case, I would usedespawn_recursive
.The root problem is that
despawn
does not automatically maintain your hierarchy.despawn_recursive
is "hierarchy aware."