#asset_server.load() Path not found (Ubuntu 22.04)

6 messages · Page 1 of 1 (latest)

neon tree
#

When spawning a sprite bundle into the window, The following code does not work, and requires me to use a FULL path to the asset.

 WARN bevy_asset::asset_server: encountered an error while reading an asset: path not found: /home/xx/DEV/RUSTY/bevy/bevy-ball-game/assets/sprites/ball_blue_large_alt.png

This is my current directory structure

bevy-ball-game
├── audio
├── sprites
├── src
└── target
pub fn spawn_player(
    mut commands: Commands,
    window_query: Query<&Window, With<PrimaryWindow>>,
    asset_server: Res<AssetServer>,
){
    let window = window_query.get_single().unwrap();

    commands.spawn(
        (
            SpriteBundle {
                transform: Transform::from_xyz(window.width() / 2.0, window.height() / 2.0, 0.0),
                texture: asset_server.load("sprites/ball_blue_large_alt.png"),
                ..default()
            },
            Player {},
        ));
}
fossil pine
#

It's cause they have to be in a directory called assets

#

I can't see a way to change it, but all you have to do it move your asset containing directories into a new directory called assets.

brazen nimbus
#

You can change it like so rs .add_plugins(DefaultPlugins.set(AssetPlugin { asset_folder: ".".into(), ..Default::default() }))

#

However it's good practice to put the assets in their own folder, and I would strongly recommend using the default unless you have a good reason not to

fossil pine
#

That makes sense, I didn't check the Plugin. Thought I can't disagree with it being good practice.
Good luck, @neon tree