Improve logging consistency for entity despawning (#6501)

* 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>
This commit is contained in:
ira 2022-11-07 19:23:34 +00:00
parent 02fbf16c80
commit 944b311c67
3 changed files with 12 additions and 12 deletions

View File

@ -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;
@ -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);
}
}

View File

@ -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
@ -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

View File

@ -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,
@ -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