Skip to content

Commit

Permalink
Use .register_asset_source() in extra_asset_source example (#12350)
Browse files Browse the repository at this point in the history
# Objective

Fixes #12347.

## Solution

Use `.register_asset_source()` in `extra_asset_source` example instead
of writing part of the app state.
  • Loading branch information
chompaa authored Mar 7, 2024
1 parent 512b746 commit f67b17d
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions examples/asset/extra_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,33 @@
//! This asset source exists in addition to the default asset source.
use bevy::asset::{
io::{AssetSourceBuilder, AssetSourceBuilders, AssetSourceId},
io::{AssetSourceBuilder, AssetSourceId},
AssetPath,
};
use bevy::prelude::*;
use std::path::Path;

fn main() {
let mut app = App::new();

// We add an extra asset source with the name "example_files" to the
// AssetSourceBuilders.
// This needs to be done before AssetPlugin finalizes building them
let mut sources = app
.world
.get_resource_or_insert_with::<AssetSourceBuilders>(default);
sources.insert(
"example_files",
AssetSourceBuilder::platform_default("examples/asset/files", None),
);

// DefaultPlugins contains AssetPlugin so it needs to be added to our App
// after inserting our new asset source
app.add_plugins(DefaultPlugins)
App::new()
// Add an extra asset source with the name "example_files" to
// AssetSourceBuilders.
//
// This must be done before AssetPlugin finalizes building assets.
.register_asset_source(
"example_files",
AssetSourceBuilder::platform_default("examples/asset/files", None),
)
// DefaultPlugins contains AssetPlugin so it must be added to our App
// after inserting our new asset source.
.add_plugins(DefaultPlugins)
.add_systems(Startup, setup)
.run();
}

fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.spawn(Camera2dBundle::default());

// Now we can load the asset using our new asset source
// Now we can load the asset using our new asset source.
//
// The actual file path relative to workspace root is
// "examples/asset/files/bevy_pixel_light.png".
Expand Down

0 comments on commit f67b17d

Please sign in to comment.