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. |
|
Closing in favor of the more incremental #22670. |
Objective
Readonly queries should not need to mutate a world, not even to initialize it. Currently the
try_queryapi exists to remedy this, but it requires all component ids, etc to be created ahead of time. This is not idea.Solution
Make all
WorldQueryjust take&Worldto 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_statenow takes&Worldinstead 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_idsnow takesComponentsQueuedRegistratorinstead of&Componentsand outputsComponentIds instead ofOption<ComponentId>.