How can I wait for a resource to be available #9181
-
My situationI have a system that will create a resource, and a system that will use that resource to create some entities at the start of the level. Here's an example of what I have so far:
A system to create that resource: A system that will use that resource to spawn some entities at the start of the level: Have an ApplicationState:
Add systems to the app:
And (separate file)
What I've triedUse When I tried this the Use SystemSet Create a LoadingSet:
Configure sets:
Add system to the set:
Same result, the Make the LoadingSet a Convert to states:
Try to use both states (compile error):
I got a compilation error trying to do this. I'm not sure if this method is impossible or just needs correct syntax. Any help is appreciated, thank you for reading. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hi, IMO the simplest thing would be to derive Default (if your res init is simple) or FromWorld (if your res needs another res or needs to set up something else - another res, entity, etc). And then you would use it |
Beta Was this translation helpful? Give feedback.
-
Your options:
|
Beta Was this translation helpful? Give feedback.
OnEnter(State)
is a schedule that only gets executed once when you change states. That means you cannot wait by letting frames run until the resource is there.Doing anything via commands means that the action is deferred until the system
apply_deferred
is called the next time. Bevy calls this system for you in some places which explains why waiting a frame works for systems that run every frame.Your options:
apply_deferred
between theminit_resource
orinsert_resource