Skip to content

Commit a5754cc

Browse files
add InteriorMutableEntityRef::get_change_ticks_by_id
1 parent b065073 commit a5754cc

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

crates/bevy_ecs/src/world/interior_mutable_world.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,34 @@ impl<'w> InteriorMutableEntityRef<'w> {
456456
}
457457
}
458458

459+
/// Retrieves the change ticks for the given [`ComponentId`]. This can be useful for implementing change
460+
/// detection in custom runtimes.
461+
///
462+
/// **You should prefer to use the typed API [`InteriorMutableEntityRef::get_change_ticks`] where possible and only
463+
/// use this in cases where the actual component types are not known at
464+
/// compile time.**
465+
///
466+
/// # Safety
467+
/// It is the callers responsibility to ensure that
468+
/// - the [`InteriorMutableEntityRef`] has permission to access the component
469+
/// - no other mutable references to the component exist at the same time
470+
#[inline]
471+
pub fn get_change_ticks_by_id(&self, component_id: ComponentId) -> Option<ComponentTicks> {
472+
let info = self.world.components().get_info(component_id)?;
473+
// SAFETY:
474+
// - entity location and entity is valid
475+
// - world access is immutable, lifetime tied to `&self`
476+
// - the storage type provided is correct for T
477+
unsafe {
478+
self.world.0.get_ticks(
479+
component_id,
480+
info.storage_type(),
481+
self.entity,
482+
self.location,
483+
)
484+
}
485+
}
486+
459487
/// # Safety
460488
/// It is the callers responsibility to ensure that
461489
/// - the [`InteriorMutableEntityRef`] has permission to access the component mutably

0 commit comments

Comments
 (0)