EntityMut::get_components_mut_unchecked()#20265
Merged
alice-i-cecile merged 1 commit intobevyengine:mainfrom Jul 23, 2025
Merged
EntityMut::get_components_mut_unchecked()#20265alice-i-cecile merged 1 commit intobevyengine:mainfrom
EntityMut::get_components_mut_unchecked()#20265alice-i-cecile merged 1 commit intobevyengine:mainfrom
Conversation
alice-i-cecile
approved these changes
Jul 23, 2025
Member
|
@tychedelia, I'd appreciate your review here as a user, especially on the safety comments. Are they clear enough that you're comfortable following them? |
tychedelia
approved these changes
Jul 23, 2025
Member
tychedelia
left a comment
There was a problem hiding this comment.
Lgtm! Docs are robust and the safety qualifications are about as straightforward as it gets for Bevy.
Contributor
Author
I agree that would be good to have, but I don't have any ideas on how to implement it (short of something like #17837). I don't think there is any way to get a |
cBournhonesque
approved these changes
Jul 23, 2025
Contributor
cBournhonesque
left a comment
There was a problem hiding this comment.
Awesome, this is a huge ergonomic improvement
github-merge-queue bot
pushed a commit
that referenced
this pull request
Sep 29, 2025
# Objective #20265 introduced a way to fetch multiple mutable components from an `EntityMut`, but it's still impossible to do so via an `FilteredEntityMut`. I believe it is currently impossible to get two mutable components from a `FilteredEntityMut`, which somewhat limits use cases with dynamic queries. ## Solution A similar solution is harder to implement for `FilteredEntityMut` because the QueryData must go through the access checks, and it's not obvious to get the ComponentIds from a `ReleaseStateQueryData`. Instead, I opt in to provide a similar abstraction as `UnsafeEntityCell` and `UnsafeWorldCell`, which are both public and Clone: an opt-in escape catch for advanced users that can guarantee that they are not causing any aliasing violations. Here, instead we provide a method that copies the underlying `UnsafeEntityCell`, so the safety requirements are similar to `UnsafeEntityCell` and `UnsafeWorldCell`. ## Testing Added a doctest. --------- Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com> Co-authored-by: Chris Russell <8494645+chescock@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Objective
Provide an unsafe way to get mutable access to multiple components from an EntityMut.
This is the API proposed in #13375, but marked
unsafeas it does not check for conflicting access.Solution
Add
unsafe fn get_components_mut_unchecked(&mut self) -> Option<Q::Item>andunsafe fn into_components_mut_unchecked(self) -> Option<Q::Item>toEntityMutandEntityWorldMut.