fix: don't recursivly despawn entities that handles depsawning themselfs

Signed-off-by: Schmarni <marnistromer@gmail.com>
This commit is contained in:
Schmarni
2025-10-31 07:40:04 +01:00
parent c8e8ae2506
commit 9f89d1a9ec
2 changed files with 16 additions and 3 deletions

View File

@@ -3,6 +3,8 @@ use std::sync::Arc;
use bevy::prelude::*;
use crate::nodes::spatial::SpatialNode;
use super::bevy_channel::{BevyChannel, BevyChannelReader};
pub struct EntityHandlePlugin;
@@ -13,9 +15,21 @@ impl Plugin for EntityHandlePlugin {
}
}
fn despawn(mut cmds: Commands, mut reader: ResMut<BevyChannelReader<Entity>>) {
fn despawn(
mut cmds: Commands,
mut reader: ResMut<BevyChannelReader<Entity>>,
child_query: Query<&Children>,
has_spatial: Query<Has<SpatialNode>>,
) {
while let Some(e) = reader.read() {
cmds.entity(e).try_despawn();
if let Ok(children) = child_query.get(e) {
for e in children {
if has_spatial.get(*e).unwrap_or_default() {
cmds.entity(*e).remove::<ChildOf>();
}
}
}
cmds.entity(e).despawn();
}
}

View File

@@ -32,7 +32,6 @@ pub struct TextNodePlugin;
impl Plugin for TextNodePlugin {
fn build(&self, app: &mut App) {
// Text init stuff
// 1.0 for font size in meters
app.add_plugins(MeshTextPlugin);
app.world_mut()
.resource_mut::<FontSettings>()