bevyengine / bevyengine/bevy

A way to iterate through directories in asset loading

Open
#11,061 0 comments 0 reactions 0 assignees View on GitHub
A-Assets C-Feature
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 16h
Merged PRs (30d)
171

Description

## What problem does this solve or what need does it fill?

It's not so much of a feature request, but a report of a feature regression. As of bevy 0.11, it was possible to walk directories while loading an asset via `load_context.asset_io().read_directory(path)`. It was a handy way to dynamically collect other files and process them as labeled side-assets. It is now impossible to do that in bevy 0.12. And as I see it, such thing would probably be a better fit for the new asset preprocession than it was earlier, but as it stand now I see two issues:
1. I would still want to opt-out preprocessor for the time being (as I am to my shame still confused by it), and since it's a feature that is completely opt-outable, I would like a way to do things like I used to do it without preprocessing;
2. Even if I were to start using asset preprocessor, still, I think there is no way to replicate what I was doing the version before ? There is [`AssetReader`](https://docs.rs/bevy/latest/bevy/asset/io/trait.AssetReader.html#), but it is unavailable in the context of asset loading ?

## What solution would you like?

I am certainly a little bit lost with the new preprocessing, so for me it would be perfect to just get an access to `AssetReader` in the loading context, i.e:
```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 {
let directories = load_context.asset_reader().read_directory("scripts").await?;
for item in directories {
// ...
}
// ...
})
}
```
This way I could upgrade parts of my codebase to bevy 0.12 without making much changes.

## What alternative(s) have you considered?

Preprocessing is a thing, and I am not totally sure if at this moment it is possible to replicate what I was doing using meta files and some clever processor.

## Additional context

I was using this feature in bevy 0.11 to build a project of teal scripts. It's a typed dialect of lua, so in the asset loader my main asset was a script project configuration, and labeled side-assets were scripts that I would transform from teal to lua. It was handy, because I didn't need to put every script into a list and save it in the configuration, it was dynamic and it was working quite well.

Contributor guide

Open the contributing guide

Research direction

Read the referenced AssetReader trait, LoadContext, and asset-loader load entry point first, then compare them with the asset preprocessing path. Done means an asset loader can iterate a directory through its loading context and support the reported dynamic side-asset use case without requiring a manually maintained file list.

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
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.