NiklasEi / bevy_asset_loader

Bevy plugin helping with asset loading and organization
Apache License 2.0
507 stars 56 forks source link

Multiple loading stages #190

Closed feelingsonice closed 9 months ago

feelingsonice commented 9 months ago

Trying to figure out if there's a way I can load different assets in multiple difference stages. An canonical example of this is:

  1. Load a config RON.
  2. From the config RON, find a path for some .png file that needs to be loaded.
  3. Load the .png file as a Image.

Right now I'm loading the config RON using bevy_asset_loader, then after the loading state, I manually load the .png file and then manually trigger another state change to a third state where "everything" is finally loaded.

I also see there's the init_resource.rs example. Very useful but seems to be for "computing" a final resource rather than loading another file. Wondering if there's a canonical approach here?

Thanks in advance :)

NiklasEi commented 9 months ago

You can have as many loading states as you like. There is no example, but a test: https://github.com/NiklasEi/bevy_asset_loader/blob/main/bevy_asset_loader/tests/multiple_loading_states.rs

feelingsonice commented 9 months ago

In this case, the 2nd step involves loading an asset based on some information from the asset loaded in the 1st step. Would I just manually register the dynamic asset in this case?

NiklasEi commented 9 months ago

Manually registering a dynamic asset resolving to the correct image should work, yes. That way you could load the second asset as part of a collection.

init_resource is not very helpful here I think, because you want to "await" the load of the second asset handle.

There is no canonical approach here at the moment, sorry.