NiklasEi / bevy_asset_loader

Bevy plugin helping with asset loading and organization
Apache License 2.0
481 stars 53 forks source link

Load collection get stuck on one state without any error messages #166

Closed miyoku157 closed 10 months ago

miyoku157 commented 10 months ago

Hi, I'm using the dynamic loader to get my assets for my levels and i want to load a custom .ron file. To do this I have this code:

pub struct TestPlugin;

#[derive(AssetCollection, Resource)]
pub struct LevelCollection {
    #[asset(key = "levels", collection(typed, mapped))]
    pub levels: HashMap<String, Handle<LevelAsset>>,
}

#[derive(serde::Deserialize, Asset, TypePath)]
pub struct LevelAsset {
    pub types: Vec<TileNum>,
}
#[derive(serde::Deserialize, Debug)]
pub struct Tile {
    pub positions: Vec3,
}
#[derive(serde::Deserialize, Debug)]
pub enum TileNum {
    Background { tiles: Vec<Tile> },
    PNJ { pnjs: Vec<PNJ> },
}
#[derive(serde::Deserialize, Debug)]
pub struct PNJ {
    pub position: Vec3,
    pub text: String,
}

impl Plugin for TestPlugin {
    fn build(&self, app: &mut App) {
        app.add_plugins(RonAssetPlugin::<LevelAsset>::new(&["level.ron"]))
            .add_collection_to_loading_state::<_, LevelCollection>(LoadStates::AssetLoading)
            .add_systems(OnEnter(LoadStates::Next), test_syst);
    }
}

Knowing that the LoadStates is already defines and the dynamic collection also. That's the dynamic assets file

({
    "levels": Folder (
        path: "levels",
    ),
    "character": File (
        path: "sprite.png",
    ),
})

And that's an example of a level file

(
    types: [
        Background(
            tiles: [
                (
                    positions: Vec3(100.0, 100.0, 0.0),
                ),
            ],
        ),
        PNJ(
            pnjs: [
                (
                    positions: Vec3(0.0, 0.0, 0.0),
                    text: "I'M A SUPER TEXT",
                ),
            ],
        ),
    ],
)

But as soon as i try to add LevelCollection to the loading state, it just get stuck without any error messages in the LoadStates::AssetLoading. Is there any way to get more log of what's happening?

NiklasEi commented 10 months ago

My first guess would be that there is an error in the de-serialization and Bevy isn't reporting it, due to bevyengine/bevy#10515 (which will be fixed with the upcoming 0.12.1 release).

One issue I can see: your example level file has positions in pnjs, but your PNJ struct only has position without s.

miyoku157 commented 10 months ago

Thanks, that was exactly the problem (i new it was something dumb from me... But i was unable to find any clue)