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

load_untyped vs Custom AssetLoaders #207

Closed
ChristopherBiscardi opened this issue Mar 30, 2024 · 4 comments
Closed

load_untyped vs Custom AssetLoaders #207

ChristopherBiscardi opened this issue Mar 30, 2024 · 4 comments

Comments

@ChristopherBiscardi
Copy link

The usage of load_untyped seems to prevent the usage of otherwise valid custom assets (AssetLoaders).

The error looks like this, where bevy_asset::server ends up not being able to find the asset loader.

Could not find an asset loader matching: Loader Name: None; Asset Type: None; Extension: None; Path: Some("uipackSpace_sheet.xml");

I am not currently sure if load_untyped is supposed to work with custom assets (bevy example). I have asked in Discord to see if anyone knows.

load_untyped is used in AssetCollection::load as seen here. I've seen the issue with both loading_state and non-loading_state bevy_asset_loader examples.

example expanded macro
// Recursive expansion of AssetCollection macro
// =============================================

#[automatically_derived]
#[allow(unused_variables)]
impl AssetCollection for ImageAssets {
    fn create(
        world: &mut ::bevy::ecs::world::World,
    ) -> Self {
        let from_world_fields = ();
        world.resource_scope(|world,asset_keys: ::bevy::prelude::Mut< ::bevy_asset_loader::dynamic_asset::DynamicAssets> |{
            ImageAssets {
                space_sheet:{
                    let asset_server = world.get_resource:: < ::bevy::asset::AssetServer>().expect("Cannot get AssetServer");
                    asset_server.load("spaceShooter2_spritesheet_2X.xml")
                },
            }
        },)
    }
    fn load(
        world: &mut ::bevy::ecs::world::World,
    ) -> Vec<::bevy::prelude::UntypedHandle> {
        let cell = world.cell();
        let asset_server = cell
            .get_resource::<::bevy::prelude::AssetServer>()
            .expect("Cannot get AssetServer");
        let asset_keys = cell.get_resource:: <bevy_asset_loader::prelude::DynamicAssets>().expect("Cannot get bevy_asset_loader::prelude::DynamicAssets");
        let mut handles = vec![];
        handles.push(
            asset_server
                .load_untyped(
                    "spaceShooter2_spritesheet_2X.xml",
                )
                .untyped(),
        );
        handles
    }
}
@NiklasEi
Copy link
Owner

Thanks for opening an issue. I am aware of the problem and don't think this is supposed to work. Bevy needs to get the correct AssetLoader, but in this case, we don't give any possible "identification" to use for loader selection (AssetLoader in .meta file, registered extension or asset type).
You are not the first user to stumble into this, but I don't think I can easily fix this in bevy_asset_loader at the moment. The macro cannot know what initial asset type needs to be loaded since, in some cases, it will be different from the asset collection field type (e.g. a StandardMaterial needs to be loaded as an Image asset first).

@NiklasEi
Copy link
Owner

I understand from the Discord discussion that you did register the xml extension in your custom asset loader. In that case I would have expected this to work.

@ChristopherBiscardi
Copy link
Author

Feeling a bit silly on this one 😅

AssetLoader::extensions must be a list of extensions without preceding dots. So [".xml"] fails with the above error while ["xml"] succeeds.

It works for me now.

@NiklasEi
Copy link
Owner

I opened #208 to see if the plugin can support asset loaders without extensions.

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