-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Assets V2 - Error whilst using load_context.load_direct() to load a LoadedFolder asset #9932
Copy link
Copy link
Open
Labels
A-AssetsLoad files from disk to use for things like images, models, and soundsLoad files from disk to use for things like images, models, and soundsC-BugAn unexpected or incorrect behaviorAn unexpected or incorrect behavior
Description
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.
fn load<'a>(
&'a self,
_reader: &'a mut Reader,
_settings: &'a Self::Settings,
load_context: &'a mut LoadContext,
) -> BoxedFuture<'a, Result<ItemMap, anyhow::Error>> {
Box::pin(async move {
// 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();
let mut 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();
if let Some(existing_item) = items.insert(item.id, item.clone()) {
return Err(anyhow::Error::msg(format!(
"Duplicate ID detected: {}",
existing_item.id
)));
}
}
Ok(ItemMap(items))
})
}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:
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: itemseven though the items directory exists.
Possibly load_context.load_direct isn't designed to handle LoadedFolder assets?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-AssetsLoad files from disk to use for things like images, models, and soundsLoad files from disk to use for things like images, models, and soundsC-BugAn unexpected or incorrect behaviorAn unexpected or incorrect behavior