diff --git a/crates/bevy_ecs/src/world/entity_ref.rs b/crates/bevy_ecs/src/world/entity_ref.rs index 5a18b3ad34..6946cb1378 100644 --- a/crates/bevy_ecs/src/world/entity_ref.rs +++ b/crates/bevy_ecs/src/world/entity_ref.rs @@ -154,7 +154,10 @@ impl<'w> EntityMut<'w> { #[inline] pub fn get(&self) -> Option<&'_ T> { // SAFE: lifetimes enforce correct usage of returned borrow - unsafe { self.get_unchecked::() } + unsafe { + get_component_with_type(self.world, TypeId::of::(), self.entity, self.location) + .map(|value| &*value.cast::()) + } } #[inline] @@ -163,23 +166,6 @@ impl<'w> EntityMut<'w> { unsafe { self.get_unchecked_mut::() } } - /// Gets an immutable reference to the component of type `T` associated with - /// this entity without ensuring there are no unique borrows active and without - /// ensuring that the returned reference will stay valid. - /// - /// # Safety - /// - /// - The returned reference must never alias a mutable borrow of this component. - /// - The returned reference must not be used after this component is moved which - /// may happen from **any** `insert_component`, `remove_component` or `despawn` - /// operation on this world (non-exhaustive list). - #[inline] - pub unsafe fn get_unchecked(&self) -> Option<&'w T> { - // SAFE: entity location is valid and returned component is of type T - get_component_with_type(self.world, TypeId::of::(), self.entity, self.location) - .map(|value| &*value.cast::()) - } - /// Gets a mutable reference to the component of type `T` associated with /// this entity without ensuring there are no other borrows active and without /// ensuring that the returned reference will stay valid.