File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed
crates/bevy_ecs/src/world Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -456,6 +456,34 @@ impl<'w> InteriorMutableEntityRef<'w> {
456
456
}
457
457
}
458
458
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
+
459
487
/// # Safety
460
488
/// It is the callers responsibility to ensure that
461
489
/// - the [`InteriorMutableEntityRef`] has permission to access the component mutably
You can’t perform that action at this time.
0 commit comments