@@ -23,7 +23,7 @@ pub struct ReflectComponent {
2323 apply_or_insert : fn ( & mut World , Entity , & dyn Reflect ) ,
2424 remove : fn ( & mut World , Entity ) ,
2525 reflect : fn ( & World , Entity ) -> Option < & dyn Reflect > ,
26- reflect_mut : unsafe fn ( & World , Entity ) -> Option < ReflectMut > ,
26+ reflect_mut : fn ( & mut World , Entity ) -> Option < ReflectMut > ,
2727 copy : fn ( & World , & mut World , Entity , Entity ) ,
2828}
2929
@@ -71,21 +71,6 @@ impl ReflectComponent {
7171
7272 /// Gets the value of this [`Component`] type from the entity as a mutable reflected reference.
7373 pub fn reflect_mut < ' a > ( & self , world : & ' a mut World , entity : Entity ) -> Option < ReflectMut < ' a > > {
74- // SAFETY: unique world access
75- unsafe { ( self . reflect_mut ) ( world, entity) }
76- }
77-
78- /// # Safety
79- /// This method does not prevent you from having two mutable pointers to the same data,
80- /// violating Rust's aliasing rules. To avoid this:
81- /// * Only call this method in an exclusive system to avoid sharing across threads (or use a
82- /// scheduler that enforces safe memory access).
83- /// * Don't call this method more than once in the same scope for a given [`Component`].
84- pub unsafe fn reflect_unchecked_mut < ' a > (
85- & self ,
86- world : & ' a World ,
87- entity : Entity ,
88- ) -> Option < ReflectMut < ' a > > {
8974 ( self . reflect_mut ) ( world, entity)
9075 }
9176
@@ -149,17 +134,10 @@ impl<C: Component + Reflect + FromWorld> FromType<C> for ReflectComponent {
149134 . map ( |c| c as & dyn Reflect )
150135 } ,
151136 reflect_mut : |world, entity| {
152- // SAFETY: reflect_mut is an unsafe function pointer used by `reflect_unchecked_mut` which promises to never
153- // produce aliasing mutable references, and reflect_mut, which has mutable world access
154- unsafe {
155- world
156- . get_entity ( entity) ?
157- . get_unchecked_mut :: < C > ( world. last_change_tick ( ) , world. read_change_tick ( ) )
158- . map ( |c| ReflectMut {
159- value : c. value as & mut dyn Reflect ,
160- ticks : c. ticks ,
161- } )
162- }
137+ world. get_mut :: < C > ( entity) . map ( |c| ReflectMut {
138+ value : c. value as & mut dyn Reflect ,
139+ ticks : c. ticks ,
140+ } )
163141 } ,
164142 }
165143 }
0 commit comments