-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow loading assets with custom async behavior #13700
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reasonable enough. I can see the use of this, and this seems reasonably constructed.
Agreed on the testing front: we need to sit down and figure out a testing strategy for bevy_assets more cohesively.
The |
This reverts commit e880938.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice idea! There's just enough complexity here (IoTaskPool
, the event_sender
, etc.) that this encapsulation really improves the user experience, but is still overall pretty simple. I concur that a better testing story is needed for bevy_asset
, but I don't think that is necessary to get this merged.
# Objective The method `AssetServer::add_async` (added in #13700) requires a future that returns an `AssetLoadError` error, which was a bit of an oversight on my part, as that type of error only really makes sense in the context of bevy's own asset loader -- returning it from user-defined futures isn't very useful. ## Solution Allow passing custom error types to `add_async`, which get cast into a trait object matching the form of `AssetLoader::load`. If merged before the next release this will not be a breaking change
# Objective The method `AssetServer::add_async` (added in #13700) requires a future that returns an `AssetLoadError` error, which was a bit of an oversight on my part, as that type of error only really makes sense in the context of bevy's own asset loader -- returning it from user-defined futures isn't very useful. ## Solution Allow passing custom error types to `add_async`, which get cast into a trait object matching the form of `AssetLoader::load`. If merged before the next release this will not be a breaking change
Objective
Currently, bevy supports custom asset loading via
AssetServer:;add
, which allows you to add arbitrary assets to the asset system and returns a handle to it. However this only works for assets that have already been fully loaded. If your loading logic involves any async, you need to wait until the asset is done loading before adding it to the server. This is problematic, as theHandle
does not get allocated until the very end, which makes it very difficult to use and defeats the value of having handles for asynchronously-loaded assets.Solution
Add the method
AssetServer::add_async
. This has the same behavior asAssetServer::add
, only it accepts a future instead of a fully loaded asset.Testing
I added an identical method to my company's fork of bevy, which works in our app. I'm not quite sure how to go about adding an actual unit test for asset loading behvior, but I will note that
AssetServer::add
also does not appear to have any tests.Changelog
AssetServer::add_async
, which allows adding assets with custom asynchronous loading behavior to theAssetServer