From e0e9794c9e3eba737bba882740b503e404deda7a Mon Sep 17 00:00:00 2001 From: AxiomaticSemantics <117950168+AxiomaticSemantics@users.noreply.github.com> Date: Sun, 25 Feb 2024 23:54:25 -0500 Subject: [PATCH] Add Archetype::component_count (#12119) Add Archetype::component_count utility method # Objective I wanted a method to count components on an archetype without iterating over them. ## Solution Added `Archetype::component_count` --------- Co-authored-by: Alice Cecile --- crates/bevy_ecs/src/archetype.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/crates/bevy_ecs/src/archetype.rs b/crates/bevy_ecs/src/archetype.rs index b333b09378..62643cf77a 100644 --- a/crates/bevy_ecs/src/archetype.rs +++ b/crates/bevy_ecs/src/archetype.rs @@ -404,6 +404,12 @@ impl Archetype { self.components.indices() } + /// Returns the total number of components in the archetype + #[inline] + pub fn component_count(&self) -> usize { + self.components.len() + } + /// Fetches a immutable reference to the archetype's [`Edges`], a cache of /// archetypal relationships. #[inline]