Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify usage of EntityWorldMut::move_entity_from_remove by making it a proper method #17360

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

JaySpruce
Copy link
Contributor

Objective

Fixes #17345

The "probably more safety stuff" was probably referring to the EntityLocation needing to be valid for the given Entity or something like that, but that's not necessary if we just give it the actual EntityWorldMut.

Solution

  • Added &mut self to move_entity_from_remove parameters.
  • Removed most of the method's other parameters and replaced them with local variables derived from self.
  • The method now directly updates the location field of the EntityWorldMut, which wasn't necessarily the case before.
    • EntityWorldMut::take passed in a mutable reference to the field, so it already worked like that.
    • EntityWorldMut::remove_bundle passed in a mutable reference to a local variable, which it then returned so that its caller could use it to update the location field. This seems unnecessarily convoluted.
  • EntityWorldMut::remove_bundle no longer returns the entity's location, as it is now updated internally.
  • Updated safety notes.
  • Added unsafe blocks to some calls that had a safety note with no block.

@BenjaminBrienen BenjaminBrienen added A-ECS Entities, components, systems, and events C-Code-Quality A section of code that is hard to understand or change D-Straightforward Simple bug fixes and API improvements, docs, test and examples D-Unsafe Touches with unsafe code in some way S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jan 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ECS Entities, components, systems, and events C-Code-Quality A section of code that is hard to understand or change D-Straightforward Simple bug fixes and API improvements, docs, test and examples D-Unsafe Touches with unsafe code in some way S-Needs-Review Needs reviewer attention (from anyone!) to move forward
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bevy_ecs::world::entity_ref::EntityWorldMut::take(), a safe function, has an undocumented unsafe block
2 participants