Skip to content

Commit 1032559

Browse files
authored
add methods to *EntityMut to UnsafeEntityCell as an escape hatch (#21234)
# Objective - Sometimes you want to break mutability rules to get multiple mutable components off of an entity. ## Solution - Allow converting the EntityMut, FilteredEntityMut, and EntityMutExcept into an UnsafeEntityCell. https://docs.rs/bevy/latest/bevy/ecs/world/unsafe_world_cell/struct.UnsafeEntityCell.html ## Testing - haven't really tested, but changes are straightforward
1 parent dbbee31 commit 1032559

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

crates/bevy_ecs/src/world/entity_ref.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,11 @@ impl<'w> EntityMut<'w> {
479479
EntityRef::from(self)
480480
}
481481

482+
/// Get access to the underlying [`UnsafeEntityCell`]
483+
pub fn as_unsafe_entity_cell(&mut self) -> UnsafeEntityCell<'_> {
484+
self.cell
485+
}
486+
482487
/// Returns the [ID](Entity) of the current entity.
483488
#[inline]
484489
#[must_use = "Omit the .id() call if you do not need to store the `Entity` identifier."]
@@ -3873,6 +3878,11 @@ impl<'w, 's> FilteredEntityMut<'w, 's> {
38733878
FilteredEntityRef::from(self)
38743879
}
38753880

3881+
/// Get access to the underlying [`UnsafeEntityCell`]
3882+
pub fn as_unsafe_entity_cell(&mut self) -> UnsafeEntityCell<'_> {
3883+
self.entity
3884+
}
3885+
38763886
/// Returns the [ID](Entity) of the current entity.
38773887
#[inline]
38783888
#[must_use = "Omit the .id() call if you do not need to store the `Entity` identifier."]
@@ -4446,6 +4456,11 @@ where
44464456
EntityRefExcept::from(self)
44474457
}
44484458

4459+
/// Get access to the underlying [`UnsafeEntityCell`]
4460+
pub fn as_unsafe_entity_cell(&mut self) -> UnsafeEntityCell<'_> {
4461+
self.entity
4462+
}
4463+
44494464
/// Gets access to the component of type `C` for the current entity. Returns
44504465
/// `None` if the component doesn't have a component of that type or if the
44514466
/// type is one of the excluded components.

0 commit comments

Comments
 (0)