-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Replace try_query
#18434
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
base: main
Are you sure you want to change the base?
Replace try_query
#18434
Conversation
We now need the user to insert the resource ahead of time. But I think that's reasonable.
I didn't realize that. Yikes. Looking at the source, I think If we can't make this work with |
Note that I think removing the |
Yeah, using resources in
Ok. I don't mind waiting for that, and components as entities, etc. This was supper easy to do, so revisiting it shouldn't be a problem. I'm still convinced we can do this now, with pretty much no cost, but I understand the argument for holding off. I'll leave the timing here up to y'all. |
Objective
Readonly queries should not need to mutate a world, not even to initialize it. Currently the
try_query
api exists to remedy this, but it requires all component ids, etc to be created ahead of time. This is not idea.Solution
Make all
WorldQuery
just take&World
to initialize. Now instead of needingtry_query
, users can just callquery
.Testing
No new tests were added, though the existing ones did catch some bugs.
Migration Guide
WorldQuery::init_state
now takes&World
instead of&mut World
. Additionally, it is now explicitly unsafe to rely on "magic" values inWorldQuery::init_state
. For example, queries can no longer access resources or entities during initialization. This was possible before but was an anti-pattern since it tied the query results to when the query was created instead of when it is queried.Additionally,
Bundle::get_component_ids
now takesComponentsQueuedRegistrator
instead of&Components
and outputsComponentId
s instead ofOption<ComponentId>
.