NiklasEi / bevy_asset_loader

Bevy plugin helping with asset loading and organization
Apache License 2.0
505 stars 56 forks source link

Panic when using `image` annotation on `Handle<Image>` field #229

Closed Gingeh closed 4 months ago

Gingeh commented 4 months ago

Using the #[asset(image(...))] on an image field causes the app to panic with "Only asset collection fields holding an Image handle can be annotated with image".

Here is an example which panics when run (with the necessary asset):

use bevy::prelude::*;
use bevy_asset_loader::prelude::*;

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .init_collection::<MyAssets>()
        .run();
}

#[derive(AssetCollection, Resource)]
struct MyAssets {
    #[asset(path = "my_image.png")]
    #[asset(image(sampler = nearest))]
    my_image: Handle<Image>,
}
NiklasEi commented 4 months ago

This is expected and I will edit the documentation to mention that the image annotation requires using a loading state.

The problem is that to change things like the sampler, I need to take the asset from the asset collection. For that, it needs to be loaded. But without a loading state, I cannot run code at the point where the asset is loaded.

NiklasEi commented 4 months ago

I opened #230 to look into supporting the image annotation without a loading state, but I consider this issue closed with the updated documentation in #231