Skip to content

Commit

Permalink
Improve logging consistency for entity despawning (bevyengine#6501)
Browse files Browse the repository at this point in the history
 * Move the despawn debug log from `World::despawn` to `EntityMut::despawn`.
 * Move the despawn non-existent warning log from `Commands::despawn` to `World::despawn`.

This should make logging consistent regardless of which of the three `despawn` methods is used.

Co-authored-by: devil-ira <justthecooldude@gmail.com>
  • Loading branch information
2 people authored and ItsDoot committed Feb 1, 2023
1 parent 7de2260 commit 6164b9e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
6 changes: 2 additions & 4 deletions crates/bevy_ecs/src/system/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
entity::{Entities, Entity},
world::{FromWorld, World},
};
use bevy_utils::tracing::{error, info, warn};
use bevy_utils::tracing::{error, info};
pub use command_queue::CommandQueue;
pub use parallel_scope::*;
use std::marker::PhantomData;
Expand Down Expand Up @@ -820,9 +820,7 @@ pub struct Despawn {

impl Command for Despawn {
fn write(self, world: &mut World) {
if !world.despawn(self.entity) {
warn!("error[B0003]: Could not despawn entity {:?} because it doesn't exist in this World.", self.entity);
}
world.despawn(self.entity);
}
}

Expand Down
2 changes: 2 additions & 0 deletions crates/bevy_ecs/src/world/entity_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::{
world::{Mut, World},
};
use bevy_ptr::{OwningPtr, Ptr, UnsafeCellDeref};
use bevy_utils::tracing::debug;
use std::{any::TypeId, cell::UnsafeCell};

/// A read-only reference to a particular [`Entity`] and all of its components
Expand Down Expand Up @@ -480,6 +481,7 @@ impl<'w> EntityMut<'w> {
}

pub fn despawn(self) {
debug!("Despawning entity {:?}", self.entity);
let world = self.world;
world.flush();
let location = world
Expand Down
16 changes: 8 additions & 8 deletions crates/bevy_ecs/src/world/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::{
system::Resource,
};
use bevy_ptr::{OwningPtr, Ptr, UnsafeCellDeref};
use bevy_utils::tracing::debug;
use bevy_utils::tracing::warn;
use std::{
any::TypeId,
cell::UnsafeCell,
Expand Down Expand Up @@ -581,13 +581,13 @@ impl World {
/// ```
#[inline]
pub fn despawn(&mut self, entity: Entity) -> bool {
debug!("Despawning entity {:?}", entity);
self.get_entity_mut(entity)
.map(|e| {
e.despawn();
true
})
.unwrap_or(false)
if let Some(entity) = self.get_entity_mut(entity) {
entity.despawn();
true
} else {
warn!("error[B0003]: Could not despawn entity {:?} because it doesn't exist in this World.", entity);
false
}
}

/// Clears component tracker state
Expand Down

0 comments on commit 6164b9e

Please sign in to comment.