diff --git a/crates/bevy_ecs/src/world/mod.rs b/crates/bevy_ecs/src/world/mod.rs index 790867764c..1bb0e74d0b 100644 --- a/crates/bevy_ecs/src/world/mod.rs +++ b/crates/bevy_ecs/src/world/mod.rs @@ -18,7 +18,10 @@ use crate::{ archetype::{ArchetypeComponentId, ArchetypeId, ArchetypeRow, Archetypes}, bundle::{Bundle, BundleInserter, BundleSpawner, Bundles}, change_detection::{MutUntyped, TicksMut}, - component::{Component, ComponentDescriptor, ComponentId, ComponentInfo, Components, Tick}, + component::{ + Component, ComponentDescriptor, ComponentId, ComponentInfo, ComponentTicks, Components, + Tick, + }, entity::{AllocAtWithoutReplacement, Entities, Entity, EntityLocation}, event::{Event, EventId, Events, SendBatchIds}, query::{DebugCheckedUnwrap, QueryData, QueryEntityError, QueryFilter, QueryState}, @@ -1255,6 +1258,26 @@ impl World { .unwrap_or(false) } + /// Retrieves the change ticks for the given resource. + pub fn get_resource_change_ticks(&self) -> Option { + self.components + .get_resource_id(TypeId::of::()) + .and_then(|component_id| self.get_resource_change_ticks_by_id(component_id)) + } + + /// Retrieves the change ticks for the given [`ComponentId`]. + /// + /// **You should prefer to use the typed API [`World::get_resource_change_ticks`] where possible.** + pub fn get_resource_change_ticks_by_id( + &self, + component_id: ComponentId, + ) -> Option { + self.storages + .resources + .get(component_id) + .and_then(|resource| resource.get_ticks()) + } + /// Gets a reference to the resource of the given type /// /// # Panics