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}, entity::{Entities, Entity},
world::{FromWorld, World}, world::{FromWorld, World},
}; };
use bevy_utils::tracing::{error, info, warn}; use bevy_utils::tracing::{error, info};
pub use command_queue::CommandQueue; pub use command_queue::CommandQueue;
pub use parallel_scope::*; pub use parallel_scope::*;
use std::marker::PhantomData; use std::marker::PhantomData;
@ -820,9 +820,7 @@ pub struct Despawn {
impl Command for Despawn { impl Command for Despawn {
fn write(self, world: &mut World) { fn write(self, world: &mut World) {
if !world.despawn(self.entity) { world.despawn(self.entity);
warn!("error[B0003]: Could not despawn entity {:?} because it doesn't exist in this World.", self.entity);
}
} }
} }

View File

@ -8,6 +8,7 @@ use crate::{
world::{Mut, World}, world::{Mut, World},
}; };
use bevy_ptr::{OwningPtr, Ptr, UnsafeCellDeref}; use bevy_ptr::{OwningPtr, Ptr, UnsafeCellDeref};
use bevy_utils::tracing::debug;
use std::{any::TypeId, cell::UnsafeCell}; use std::{any::TypeId, cell::UnsafeCell};
/// A read-only reference to a particular [`Entity`] and all of its components /// 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) { pub fn despawn(self) {
debug!("Despawning entity {:?}", self.entity);
let world = self.world; let world = self.world;
world.flush(); world.flush();
let location = world let location = world

View File

@ -20,7 +20,7 @@ use crate::{
system::Resource, system::Resource,
}; };
use bevy_ptr::{OwningPtr, Ptr, UnsafeCellDeref}; use bevy_ptr::{OwningPtr, Ptr, UnsafeCellDeref};
use bevy_utils::tracing::debug; use bevy_utils::tracing::warn;
use std::{ use std::{
any::TypeId, any::TypeId,
cell::UnsafeCell, cell::UnsafeCell,
@ -581,13 +581,13 @@ impl World {
/// ``` /// ```
#[inline] #[inline]
pub fn despawn(&mut self, entity: Entity) -> bool { pub fn despawn(&mut self, entity: Entity) -> bool {
debug!("Despawning entity {:?}", entity); if let Some(entity) = self.get_entity_mut(entity) {
self.get_entity_mut(entity) entity.despawn();
.map(|e| {
e.despawn();
true true
}) } else {
.unwrap_or(false) warn!("error[B0003]: Could not despawn entity {:?} because it doesn't exist in this World.", entity);
false
}
} }
/// Clears component tracker state /// Clears component tracker state