bevy
bevy copied to clipboard
Allow `AssetServer::load` to acquire a guard item.
Objective
Supercedes #12881 . Added a simple implementation that allows the user to react to multiple asset loads both synchronously and asynchronously.
Solution
Added load_acquire, that holds an item and drops it when loading is finished or failed.
When used synchronously
Hold an Arc<()>, check for Arc::strong_count() == 1 when all loading completed.
When used asynchronously
Hold a SemaphoreGuard, await on acquire_all for completion.
This implementation has more freedom than the original in my opinion.
The generated examples/README.md is out of sync with the example metadata in Cargo.toml or the example readme template. Please run cargo run -p build-templated-pages -- update examples to update it, and commit the file change.
The generated examples/README.md is out of sync with the example metadata in Cargo.toml or the example readme template. Please run cargo run -p build-templated-pages -- update examples to update it, and commit the file change.
Could you add an example demonstrating how one might use this? This seems like a really neat design, but making the jump from "cool API" to "practical use" has been a perpetual challenge for users of bevy_asset.
Added an example to show how this works.
Okay, that example was super useful! I now understand the point of this PR much better, and now it can be more easily taught and tested.
I've left a few comments for suggestions on how to make the example a bit gentler on beginners :) I think that I would also hook into Bevy's states to define whether or not asset loading is done, but I'm happy to get pushback if you feel otherwise.
Thanks! I made a few more updates to the example. I think it is now more useful as a template or as a guide to beginners.