Assets V2 - Error whilst using load_context.load_direct() to load a LoadedFolder asset
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 171
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.
```rust
fn load<'a>(
&'a self,
_reader: &'a mut Reader,
_settings: &'a Self::Settings,
load_context: &'a mut LoadContext,
) -> BoxedFuture<'a, Result> {
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::().unwrap();
let mut items: HashMap = 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::().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:
```rust
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?
Contributor guide
Research direction
Start with the linked preprocessing_loaded_folder_testing reproduction and the AssetLoader entry point using load_context.load_direct("items"). Read the LoadedFolder and load_direct behavior around directory paths and preprocessing, then verify the fix against the reported error and the example's asset-loading flow.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- game-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100