NiklasEi / bevy_asset_loader

Bevy plugin helping with asset loading and organization
Apache License 2.0
474 stars 52 forks source link

Error when using `progress_tracking` and `progress_tracking_stageless` features #72

Closed arewerage closed 2 years ago

arewerage commented 2 years ago

When trying to delay the end of loading assets using iyes_progress, an error occurs:

thread 'main' panicked at 'State Transiton Stage not found (assuming auto-added label)', C:\Users\Anton\.cargo\registry\src\github.com-1ecc6299db9ec823\iyes_loopless-0.5.1\src\state.rs:239:25
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
error: process didn't exit successfully: `target\debug\bevy_template.exe` (exit code: 101)

bevy: 0.7 bevy_asset_loader: branch main

Cargo.toml:

[features]
default = [
    # https://github.com/bevyengine/bevy/blob/main/docs/cargo_features.md
    "bevy/bevy_winit",
    "bevy/render",
    "bevy/png",

    "bevy_asset_loader/2d",
    "bevy_asset_loader/dynamic_assets",
    "bevy_asset_loader/stageless",
    "bevy_asset_loader/progress_tracking",
    "bevy_asset_loader/progress_tracking_stageless",
]

dev = [
    "bevy/dynamic",
]

[dependencies]
bevy = { version = "0.7", default-features = false }
iyes_loopless = { git = "https://github.com/NiklasEi/iyes_loopless", branch = "loopless-schedule-ext-trait" }
bevy-inspector-egui = "0.11.0"
bevy_asset_loader = { git = "https://github.com/NiklasEi/bevy_asset_loader", branch = "main" }
iyes_progress = "0.3.0"

lib.rs:

mod loading;

use bevy::prelude::*;
use iyes_loopless::prelude::*;

pub struct GamePlugin;

impl Plugin for GamePlugin {
    fn build(&self, app: &mut App) {
        app.add_loopless_state(GameState::Loading)
            .add_plugin(loading::LoadingPlugin);
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum GameState {
    Loading,
    MainMenu,
    Gameplay,
}

loading.rs:

use bevy::prelude::*;
use bevy_asset_loader::prelude::*;
use iyes_loopless::prelude::*;
use iyes_progress::{ProgressCounter, ProgressPlugin};

use crate::GameState;

const TIME_FOR_SPLASH_SCREEN: f64 = 5.0;

pub struct LoadingPlugin;

impl Plugin for LoadingPlugin {
    fn build(&self, app: &mut App) {
        app.add_loading_state(
            LoadingState::new(GameState::Loading)
                .continue_to_state(GameState::MainMenu)
                .with_dynamic_collections::<StandardDynamicAssetCollection>(vec!["dynamic.assets"])
                .with_collection::<ImageAssets>()
                .with_collection::<AudioAssets>()
                .with_collection::<FontAssets>(),
        )
        .add_plugin(ProgressPlugin::new(GameState::Loading))
        .add_system(make_loading_delay.run_in_state(GameState::Loading));
    }
}

#[derive(AssetCollection)]
struct ImageAssets {}

#[derive(AssetCollection)]
struct AudioAssets {}

#[derive(AssetCollection)]
struct FontAssets {}

fn make_loading_delay(time: Res<Time>, progress: Res<ProgressCounter>) {
    let condition = time.seconds_since_startup() > TIME_FOR_SPLASH_SCREEN;
    progress.manually_track(condition.into());
}
NiklasEi commented 2 years ago

Are you adding the GamePlugin before the LoadingPlugin? The stageless state needs to be configured before the loading state.

arewerage commented 2 years ago

main.rs:

#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]

use bevy::prelude::{default, App, ClearColor, Color, DefaultPlugins, WindowDescriptor};
use bevy_template::GamePlugin;

fn main() {
    App::new()
        .insert_resource(ClearColor(Color::GRAY))
        .insert_resource(WindowDescriptor {
            title: "Bevy Template".to_string(),
            width: 1280.0,
            height: 720.0,
            ..default()
        })
        .add_plugins(DefaultPlugins)
        .add_plugin(GamePlugin)
        .run();
}
NiklasEi commented 2 years ago

Sorry, I missed the add_plugin in the GamePlugin. This looks Ok.

NiklasEi commented 2 years ago

Does the stageless_progress example run for you?

Is your project code available somewhere (if not I can work with the code blocks above)? I won't be back at my computer for a while, but when I am, I'll take a closer look.

arewerage commented 2 years ago

In the next couple of hours I will publish the latest version of the project on github and give a link.

And also check the work of stageless_progress

NiklasEi commented 2 years ago

I realized what the issue was and quickly fixed it. The progress feature was pulling in a different version of iyes_loopless, so the stage-label types didn't match anymore. Please use a git dependency for iyes_progress like on main now and run a cargo update.

arewerage commented 2 years ago

Thank you very much)