@@ -82,6 +82,22 @@ impl<'w> EntityRef<'w> {
82
82
unsafe { get_ticks_with_type ( self . world , TypeId :: of :: < T > ( ) , self . entity , self . location ) }
83
83
}
84
84
85
+ /// Retrieves the change ticks for the given [`ComponentId`]. This can be useful for implementing change
86
+ /// detection in custom runtimes.
87
+ ///
88
+ /// **You should prefer to use the typed API [`EntityRef::get_change_ticks`] where possible and only
89
+ /// use this in cases where the actual component types are not known at
90
+ /// compile time.**
91
+ #[ inline]
92
+ pub fn get_change_ticks_by_id ( & self , component_id : ComponentId ) -> Option < ComponentTicks > {
93
+ if !self . contains_id ( component_id) {
94
+ return None ;
95
+ }
96
+
97
+ // SAFETY: Entity location is valid and component_id exists.
98
+ unsafe { get_ticks ( self . world , component_id, self . entity , self . location ) }
99
+ }
100
+
85
101
/// Gets a mutable reference to the component of type `T` associated with
86
102
/// this entity without ensuring there are no other borrows active and without
87
103
/// ensuring that the returned reference will stay valid.
@@ -206,6 +222,22 @@ impl<'w> EntityMut<'w> {
206
222
unsafe { get_ticks_with_type ( self . world , TypeId :: of :: < T > ( ) , self . entity , self . location ) }
207
223
}
208
224
225
+ /// Retrieves the change ticks for the given [`ComponentId`]. This can be useful for implementing change
226
+ /// detection in custom runtimes.
227
+ ///
228
+ /// **You should prefer to use the typed API [`EntityMut::get_change_ticks`] where possible and only
229
+ /// use this in cases where the actual component types are not known at
230
+ /// compile time.**
231
+ #[ inline]
232
+ pub fn get_change_ticks_by_id ( & self , component_id : ComponentId ) -> Option < ComponentTicks > {
233
+ if !self . contains_id ( component_id) {
234
+ return None ;
235
+ }
236
+
237
+ // SAFETY: Entity location is valid and component_id exists.
238
+ unsafe { get_ticks ( self . world , component_id, self . entity , self . location ) }
239
+ }
240
+
209
241
/// Gets a mutable reference to the component of type `T` associated with
210
242
/// this entity without ensuring there are no other borrows active and without
211
243
/// ensuring that the returned reference will stay valid.
0 commit comments