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

Reconsider removing WorldCell #12549

Closed
alice-i-cecile opened this issue Mar 18, 2024 · 3 comments · Fixed by #12551
Closed

Reconsider removing WorldCell #12549

alice-i-cecile opened this issue Mar 18, 2024 · 3 comments · Fixed by #12551
Labels
A-ECS Entities, components, systems, and events C-Code-Quality A section of code that is hard to understand or change C-Usability A targeted quality-of-life change that makes Bevy easier to use S-Ready-For-Implementation This issue is ready for an implementation PR. Go for it!

Comments

@alice-i-cecile
Copy link
Member

          Our internal uses of `World::cell` outside of tests is now at 0. It might be a good time to revisit this now that we have `UnsafeWorldCell` and `DeferredWorld`.

Originally posted by @james7132 in #3939 (comment)

@alice-i-cecile alice-i-cecile added A-ECS Entities, components, systems, and events C-Code-Quality A section of code that is hard to understand or change C-Usability A targeted quality-of-life change that makes Bevy easier to use labels Mar 18, 2024
@AxiomaticSemantics
Copy link
Contributor

I took some time and removed ArchetypeComponentAccess out of world and disconnecting world_cell module from the tree and things seemed to test out and work fine after.

@james7132
Copy link
Member

Note that WorldCell is the primary way to (safely) fetch multiple resources (as requested in #2942) right now. Either that needs to be resolved in another way or we should flesh out WorldCell's APIs. The third option is to encourage use of SystemState as it's both safe, and retains a cache to make fetches faster in the future.

I'm in favor of the third option. Though it's a bit unwieldy to use right now, it offers the best option to provide safe and performant access at runtime, it logically scales well as users are already familiar with the system param DSL, it lets us maintain less code (by removing the need for WorldCell), and supports more than just resources (really any arbitrary SystemParam, including Queries).

@alice-i-cecile
Copy link
Member Author

Agreed on the third option as the standard migration path. This is what I use in my own code (or sometimes resource_scope if the pattern supports it).

A fully fleshed out version built out of UnsafeWorldCell might be a nice third-party crate for users who find themselves running into these problems regularly and are okay with panics. That work should likely be based on bevyengine/rfcs#42.

@alice-i-cecile alice-i-cecile added the S-Ready-For-Implementation This issue is ready for an implementation PR. Go for it! label Mar 18, 2024
github-merge-queue bot pushed a commit that referenced this issue Mar 18, 2024
# Objective
Fixes #12549. WorldCell's support of everything a World can do is
incomplete, and represents an alternative, potentially confusing, and
less performant way of pulling multiple fetches from a `World`. The
typical approach is to use `SystemState` for a runtime cached and safe
way, or `UnsafeWorldCell` if the use of `unsafe` is tolerable.

## Solution
Remove it!

---

## Changelog
Removed: `WorldCell`
Removed: `World::cell`

## Migration Guide
`WorldCell` has been removed. If you were using it to fetch multiple
distinct values from a `&mut World`, use `SystemState` by calling
`SystemState::get` instead. Alternatively, if `SystemState` cannot be
used, `UnsafeWorldCell` can instead be used in unsafe contexts.
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 C-Usability A targeted quality-of-life change that makes Bevy easier to use S-Ready-For-Implementation This issue is ready for an implementation PR. Go for it!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants