Replies: 2 comments 1 reply
-
My recommendation would be to not worry about the performance impact of the scheduler checking the app's current state. You're going to want to use states in your app anyway, and the cost of this weighed against the rest of the logic in your app will be extremely small. A bit of confusion regarding These links would be good starting points. https://github.com/bevyengine/bevy/blob/main/examples/ecs/state.rs |
Beta Was this translation helpful? Give feedback.
-
Once assets become entities, surely it'll be possible to use an observer to detect when an asset has finished loading and then run your code just once? Or is there already a mechanic to do something similar today? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Motivational example
My game needs to load a configuration
.json
file toward the beginning of the game, then parse it and load other assets depending on what's inside the.json
configuration. Many other things cannot happen before this is finished (think of it as a loading screen and preparing assets for what's next). I think that this is a reasonably common use case.Because
AssetServer
is asynchronous in nature (see #3129), it's impossible in general to run the following in sequence:Side note: I know I can use directly
File::open()
and workaround the issue by having a blocking load. However this is:File::open()
doesn't workAssetServer
and one via direct loading, one of which Bevy knows about and the other it doesn'tInstead, it seems the recommended way according to the
custom_asset.rs
example is to have a system that polls for the loading state and eventually when the asset is loaded use it.Generalization
The above asset loading pattern is not only quite a lot a boilerplate code to write, it seems that it will leave registered a system that forever will be ticked (or, as an optimization, has a
RunCriteria
that will get checked, but that's marginally better) each frame for the rest of the application lifetime.More generally, it seems many one-off jobs like this leave behind them a system that is no longer of any use. This can be optimized I believe by having a dedicated
State
for the job or set of jobs, but the state itself is also implemented as aRunCriteria
, so will still leave behind that check every frame forever.I suspect that the rationale behind that design is that with a single global state enum (or a few of them), the number of per-frame checks is low. Nonetheless it's 1) non-zero; 2) as far as I know not really well documented as a pattern so may have limitations or drawbacks I don't know;
3) possibly moot since there's some talk about removing[EDIT:Stage
completely (#1375, #2801)Stage
but notState
].Problem statement
What is a recommended pattern for one-off jobs without impacting too much performance and cluttering the schedule graph? And ideally without having to write too much boilerplate too. Should/could we allow un-registering a system from the ECS scheduler?
Beta Was this translation helpful? Give feedback.
All reactions