Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for nested folders #41

Closed
makspll opened this issue Apr 28, 2022 · 5 comments
Closed

Support for nested folders #41

makspll opened this issue Apr 28, 2022 · 5 comments

Comments

@makspll
Copy link

makspll commented Apr 28, 2022

I would love to see some support for nested folder structures, for example:

- assets
    - scripts 
         - init.lua
         - hello.lua
         - more_scripts
             - script.lua

perhaps in the form of an argument to the asset attribute, maybe recursive ?

struct LuaAssets {
    #[asset(path = "scripts", folder(typed), recursive(true))]
    folder: Vec<Handle<LuaFile>>
}

alternatively the folder could be modelled as a dictionary, with keys representing the relative/absolute paths, in case these have some meaning to the developer.

In the case that the folder contains mixed assets, these could simply be ignored to accommodate use-cases where different asset types must be stored alongside each other.

Happy to help if necessary!

@NiklasEi
Copy link
Owner

NiklasEi commented Apr 30, 2022

Under the hood, bevy_asset_loader is just using Bevy's load_folder here, which already is recursive. Your example should work without any new attribute needed. Does it not work for you?

Filtering for specific types is something I would see in the engine, not in this plugin. Possible APIs in Bevy have been discussed before (see e.g. bevyengine/bevy#2292).

@makspll
Copy link
Author

makspll commented Apr 30, 2022

Ah! I wasn't aware of the resistivity of folder loading! Perhaps it's me being blind or maybe this could be made clearer in the docs ?

Maybe it would be worth changing:

You can load all assets in a folder and keep them in an AssetCollection as a vector of untyped handles.

to:

You can recursively load all assets in a folder and keep them in an AssetCollection as a vector of untyped handles.

That's brilliant!

I guess this is also highly coupled to bevy's asset loader but would it be possible to support populating a mapping from relative paths to the handles instead of a simple Vec ?

This would likely involve searching the directory tree manually and then loading each asset individually (i.e. bypassing the load_folder, method), not sure if that's something you'd consider, but It would definitely be useful. One use case I can think of is storing prefabs under folders and linking their corresponding assets based on the path.

@NiklasEi
Copy link
Owner

I added a note in the readme about the recursive behaviour of loading a folder, thanks for pointing that out.

Keeping a path map for files in directories is also something I would see in the engine. This kind of behaviour also depends on your environment (e.g. usually non of this works in the browser) and should be baked into Bevy's AssetServer in my opinion. Maybe you want to file an issue on the engine repo for this? Once Bevy can do this, I would definitely add support here.

@makspll
Copy link
Author

makspll commented Apr 30, 2022

No worries,

Yeah that sounds very reasonable, I will go ahead and file an issue.

Thanks!

@makspll makspll closed this as completed Apr 30, 2022
@makspll
Copy link
Author

makspll commented Apr 30, 2022

I see an issue for something like this already exists, I will link it here:
bevyengine/bevy#2147

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants