Replies: 1 comment
-
you might be able to use try_query to construct a QueryState https://docs.rs/bevy/latest/bevy/ecs/world/struct.DeferredWorld.html#method.try_query |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Context
I’m updating my project from Bevy 0.16 → 0.17, and ran into a problem with lifecycle hooks and the new
DeferredWorld
API.In 0.16 I used to do this inside an
on_insert
:That worked fine, but
iter_entities()
is now deprecated in 0.17.The migration guide says to use
world.query::<EntityRef>().iter(&world)
, but that doesn’t compile withDeferredWorld
because it requires a&mut World
or an existingQueryState
.Is there a safe way to query components (e.g.
Window
withPrimaryWindow
) from inside anon_insert
hook now?I’ve explored:
world.query::<&Window, With<PrimaryWindow>>()
→ not available forDeferredWorld
QueryState::<&Window>::new_from_world_cell()
→ works but requiresunsafe
iter_entities()
→ works but noisyAdded<Background>
→ safe but loses hook immediacyI’d like to stay within the hook and keep things safe and modern—no
unsafe
or deprecated calls—if that’s possible.Thoughts
Is this currently an oversight or intentional restriction of
DeferredWorld
?If there’s a new recommended approach to “look up other components/resources” inside hooks in 0.17, I’d love to learn it.
Versions
Beta Was this translation helpful? Give feedback.
All reactions