From c65ef19b7caddaf9e47e7682be5d06a2df61e217 Mon Sep 17 00:00:00 2001 From: Carter Anderson Date: Wed, 9 Jul 2025 12:15:37 -0700 Subject: [PATCH] Friendlier Entity Debug impl (#20045) # Objective The current Entity Debug impl prints the bit representation. This is an "overshare". Debug is in many ways the primary interface into Entity, as people derive Debug on their entity-containing types when they want to inspect them. The bits take up too much space in the console and obfuscate the useful information (entity index and generation). ## Solution Use the Display implementation in Debug as well. Direct people interested in bits to `Entity::to_bits` in the docs. --- crates/bevy_ecs/src/entity/mod.rs | 36 +++++-------------------------- 1 file changed, 5 insertions(+), 31 deletions(-) diff --git a/crates/bevy_ecs/src/entity/mod.rs b/crates/bevy_ecs/src/entity/mod.rs index 700a4e517f..64a8c8952e 100644 --- a/crates/bevy_ecs/src/entity/mod.rs +++ b/crates/bevy_ecs/src/entity/mod.rs @@ -615,42 +615,16 @@ impl<'de> Deserialize<'de> for Entity { } } -/// Outputs the full entity identifier, including the index, generation, and the raw bits. +/// Outputs the short entity identifier, including the index and generation. /// -/// This takes the format: `{index}v{generation}#{bits}`. +/// This takes the format: `{index}v{generation}`. /// /// For [`Entity::PLACEHOLDER`], this outputs `PLACEHOLDER`. /// -/// # Usage -/// -/// Prefer to use this format for debugging and logging purposes. Because the output contains -/// the raw bits, it is easy to check it against serialized scene data. -/// -/// Example serialized scene data: -/// ```text -/// ( -/// ... -/// entities: { -/// 4294967297: ( <--- Raw Bits -/// components: { -/// ... -/// ), -/// ... -/// ) -/// ``` +/// For a unique [`u64`] representation, use [`Entity::to_bits`]. impl fmt::Debug for Entity { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - if self == &Self::PLACEHOLDER { - write!(f, "PLACEHOLDER") - } else { - write!( - f, - "{}v{}#{}", - self.index(), - self.generation(), - self.to_bits() - ) - } + fmt::Display::fmt(self, f) } } @@ -1645,7 +1619,7 @@ mod tests { fn entity_debug() { let entity = Entity::from_raw(EntityRow::new(NonMaxU32::new(42).unwrap())); let string = format!("{entity:?}"); - assert_eq!(string, "42v0#4294967253"); + assert_eq!(string, "42v0"); let entity = Entity::PLACEHOLDER; let string = format!("{entity:?}");