Skip to content

Commit

Permalink
Add a doc note about despawn footgun
Browse files Browse the repository at this point in the history
  • Loading branch information
benfrankel committed Dec 6, 2023
1 parent f683b80 commit ad4932d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
12 changes: 12 additions & 0 deletions crates/bevy_ecs/src/system/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,12 @@ impl<'w, 's, 'a> EntityCommands<'w, 's, 'a> {
///
/// See [`World::despawn`] for more details.
///
/// # Note
///
/// This won't clean up external references to the entity, which will leave the
/// hierarchy in an invalid state if the entity has a parent or any children. You can use
/// `despawn_recursive` or `despawn_descendants` instead to preserve the hierarchy.
///
/// # Panics
///
/// The command will panic when applied if the associated entity does not exist.
Expand Down Expand Up @@ -1062,6 +1068,12 @@ where

/// A [`Command`] that despawns a specific entity.
/// This will emit a warning if the entity does not exist.
///
/// # Note
///
/// This won't clean up external references to the entity, which will leave the
/// hierarchy in an invalid state if the entity has a parent or any children. You can use
/// `DespawnRecursive` or `DespawnDescendants` instead to preserve the hierarchy.
#[derive(Debug)]
pub struct Despawn {
/// The entity that will be despawned.
Expand Down
6 changes: 6 additions & 0 deletions crates/bevy_ecs/src/world/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,12 @@ impl World {
/// Despawns the given `entity`, if it exists. This will also remove all of the entity's
/// [`Component`]s. Returns `true` if the `entity` is successfully despawned and `false` if
/// the `entity` does not exist.
///
/// # Note
///
/// This won't clean up external references to the entity, which will leave the
/// hierarchy in an invalid state if the entity has a parent or any children.
///
/// ```
/// use bevy_ecs::{component::Component, world::World};
///
Expand Down

0 comments on commit ad4932d

Please sign in to comment.