diff --git a/crates/bevy_ecs/src/world/mod.rs b/crates/bevy_ecs/src/world/mod.rs index 22add5b970365..be4da961ce881 100644 --- a/crates/bevy_ecs/src/world/mod.rs +++ b/crates/bevy_ecs/src/world/mod.rs @@ -17,13 +17,13 @@ use crate::{ storage::{Column, SparseSet, Storages}, system::Resource, }; +use bevy_utils::tracing::debug; use std::{ any::TypeId, fmt, mem::ManuallyDrop, sync::atomic::{AtomicU32, Ordering}, }; - mod identifier; pub use identifier::WorldId; @@ -464,6 +464,7 @@ impl World { /// ``` #[inline] pub fn despawn(&mut self, entity: Entity) -> bool { + debug!("Despawning entity {:?}", entity); self.get_entity_mut(entity) .map(|e| { e.despawn(); diff --git a/crates/bevy_hierarchy/src/hierarchy.rs b/crates/bevy_hierarchy/src/hierarchy.rs index 56c9b0f8ad938..4d6753e719089 100644 --- a/crates/bevy_hierarchy/src/hierarchy.rs +++ b/crates/bevy_hierarchy/src/hierarchy.rs @@ -9,13 +9,15 @@ use bevy_utils::tracing::debug; /// Despawns the given entity and all its children recursively #[derive(Debug)] pub struct DespawnRecursive { - entity: Entity, + /// Target entity + pub entity: Entity, } /// Despawns the given entity's children recursively #[derive(Debug)] pub struct DespawnChildrenRecursive { - entity: Entity, + /// Target entity + pub entity: Entity, } /// Function for despawning an entity and all its children @@ -54,12 +56,26 @@ fn despawn_children(world: &mut World, entity: Entity) { impl Command for DespawnRecursive { fn write(self, world: &mut World) { + #[cfg(feature = "trace")] + let _span = bevy_utils::tracing::info_span!( + "command", + name = "DespawnRecursive", + entity = bevy_utils::tracing::field::debug(self.entity) + ) + .entered(); despawn_with_children_recursive(world, self.entity); } } impl Command for DespawnChildrenRecursive { fn write(self, world: &mut World) { + #[cfg(feature = "trace")] + let _span = bevy_utils::tracing::info_span!( + "command", + name = "DespawnChildrenRecursive", + entity = bevy_utils::tracing::field::debug(self.entity) + ) + .entered(); despawn_children(world, self.entity); } } @@ -90,6 +106,14 @@ impl<'w> DespawnRecursiveExt for EntityMut<'w> { /// Despawns the provided entity and its children. fn despawn_recursive(mut self) { let entity = self.id(); + + #[cfg(feature = "trace")] + let _span = bevy_utils::tracing::info_span!( + "despawn_recursive", + entity = bevy_utils::tracing::field::debug(entity) + ) + .entered(); + // SAFE: EntityMut is consumed so even though the location is no longer // valid, it cannot be accessed again with the invalid location. unsafe { @@ -99,6 +123,14 @@ impl<'w> DespawnRecursiveExt for EntityMut<'w> { fn despawn_descendants(&mut self) { let entity = self.id(); + + #[cfg(feature = "trace")] + let _span = bevy_utils::tracing::info_span!( + "despawn_descendants", + entity = bevy_utils::tracing::field::debug(entity) + ) + .entered(); + // SAFE: The location is updated. unsafe { despawn_children(self.world_mut(), entity); diff --git a/crates/bevy_internal/Cargo.toml b/crates/bevy_internal/Cargo.toml index 766e4c8a709cf..d174fa7b1f19c 100644 --- a/crates/bevy_internal/Cargo.toml +++ b/crates/bevy_internal/Cargo.toml @@ -10,7 +10,14 @@ keywords = ["game", "engine", "gamedev", "graphics", "bevy"] categories = ["game-engines", "graphics", "gui", "rendering"] [features] -trace = [ "bevy_app/trace", "bevy_ecs/trace", "bevy_log/trace", "bevy_render/trace", "bevy_core_pipeline/trace" ] +trace = [ + "bevy_app/trace", + "bevy_core_pipeline/trace", + "bevy_ecs/trace", + "bevy_log/trace", + "bevy_render/trace", + "bevy_transform/trace" +] trace_chrome = [ "bevy_log/tracing-chrome" ] trace_tracy = [ "bevy_log/tracing-tracy" ] wgpu_trace = ["bevy_render/wgpu_trace"] diff --git a/crates/bevy_transform/Cargo.toml b/crates/bevy_transform/Cargo.toml index 572f9378ca347..0102cbf203c07 100644 --- a/crates/bevy_transform/Cargo.toml +++ b/crates/bevy_transform/Cargo.toml @@ -8,6 +8,9 @@ repository = "https://github.com/bevyengine/bevy" license = "MIT OR Apache-2.0" keywords = ["bevy"] +[features] +trace = [] + [dependencies] # bevy bevy_app = { path = "../bevy_app", version = "0.7.0-dev" }