You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to implement a many -> 1 AssetLoader for item assets in my game.
e.g. there could be 100s of item assets, and I just want to combine them into one ItemMap asset.
Rather than manually maintaining a meta asset which just lists out the paths to each of these item assets, I'm trying to use a LoadedFolder within the AssetLoader to retrieve every item asset within a directory.
e.g.
fnload<'a>(&'aself,_reader:&'amutReader,_settings:&'aSelf::Settings,load_context:&'amutLoadContext,) -> BoxedFuture<'a,Result<ItemMap, anyhow::Error>>{Box::pin(asyncmove{// Load all item assets within the /assets/items directory (as a LoadedFolder asset)let loaded_folder = load_context.load_direct("items").await?;let folder = loaded_folder.get::<LoadedFolder>().unwrap();letmut items:HashMap<u64,Item> = HashMap::new();// Populate the ItemMap (and check for duplicate IDs)for handle in&folder.handles{let loaded_item = load_context.load_direct(handle.path().unwrap()).await?;let item = loaded_item.get::<Item>().unwrap();ifletSome(existing_item) = items.insert(item.id, item.clone()){returnErr(anyhow::Error::msg(format!("Duplicate ID detected: {}",
existing_item.id
)));}}Ok(ItemMap(items))})}
ERROR bevy_asset::server:Asset'all.items.ron' encountered an error in preprocessing_loaded_folder_testing::assets::ItemMapAssetLoader:Failed to load dependency items path not found: items
even though the items directory exists.
Possibly load_context.load_direct isn't designed to handle LoadedFolder assets?
The text was updated successfully, but these errors were encountered:
cart
added
A-Assets
Load files from disk to use for things like images, models, and sounds
and removed
S-Needs-Triage
This issue needs to be labelled
labels
Sep 27, 2023
Yup load_direct is the "direct" equivalent to load, which does not support folders. In apps, there is a separate load_folder api for that.
However in loaders and processors, we do not currently have a load_folder_direct api. This is largely because it introduces additional complexity when it comes to determining when a dependency changes.
We need to be able to re-run processors whenever the "processor dependencies" change (aka "x_direct" calls). Currently, with load_direct(some_path), we can just add some_path to the processor dependencies for the asset and then re-process whenever some_path changes.
For some load_folder_direct api, we can't just append a list of the files currently in the folder to the dependency list, as that isn't what the actual "requested input" is. We need a new concept of "folder dependencies" that allows us to reprocess an asset (using load_folder_direct(some_folder)) whenever any asset in the some_folder is added, removed, or changed. This is possible, but it will require some careful engineering.
Bevy version
0.12-dev
What you did
I'm trying to implement a many -> 1 AssetLoader for item assets in my game.
e.g. there could be 100s of item assets, and I just want to combine them into one ItemMap asset.
Rather than manually maintaining a meta asset which just lists out the paths to each of these item assets, I'm trying to use a LoadedFolder within the AssetLoader to retrieve every item asset within a directory.
e.g.
I've uploaded an example repo here: https://github.com/66OJ66/preprocessing_loaded_folder_testing
What went wrong
In short, this approach yields an error:
even though the
items
directory exists.Possibly
load_context.load_direct
isn't designed to handle LoadedFolder assets?The text was updated successfully, but these errors were encountered: