#Res is not being delivered

10 messages · Page 1 of 1 (latest)

graceful slate
#

I load resource like this

#[img_handle_resource(path = "test.png")]
pub struct ShipPlaceholder;

pub fn load_all_sprites(mut commands: Commands, asset_server: Res<AssetServer>) {
    commands.insert_resource(ShipPlaceholder { img: asset_server.load(ShipPlaceholder::asset_path())} );
}

Then I'm trying to use like this

fn load_sprite(mut commands: Commands, texture: Option<Res<ShipPlaceholder>>) {
    commands.spawn(SpriteBundle {
        texture: texture.expect("no ship placeholder").img.clone(),
        sprite: Sprite {
            ..default()
        },
        ..default()
    });
}

and i call these in this way:


fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_plugin(FramepacePlugin)
        .add_startup_system(setup)
        .add_startup_system(load_all_sprites)
        .add_startup_system(load_sprite)
        .add_startup_system(set_fps_limit)
        .add_plugin(LogDiagnosticsPlugin::default())
        .run();
}

but this one not works with thread 'main' panicked at 'no ship placeholder', which means resource is not delivered, why?

jagged ember
#

You'll need to use stages

#

you could also use different states, one for loading assets, one for spawning

graceful slate
#

well. this not works: .add_stage_after(StartupStage::Startup, Label::Load, SystemStage::parallel()) .add_system_to_stage(Label::Load, load_all_sprites) .add_stage_after(Label::Load, Label::Spawn, SystemStage::parallel()) .add_system_to_stage(Label::Spawn, load_sprite) because it cannot find startup stage

#

direct system ordering now toworks either but update works

#

i don't think it is a good idea pu this to update

jagged ember
#

add_startup_system_to_stage

graceful slate
#

Well this one wants system stages which limits all stuff effectively to 2 steps, is there a wya to get around this?

#

Thanks anyway

jagged ember
#

It might be that commands aren't run until end of a startup system, unsure. I have run into this and worked around it a few ways, states where it makes sense.