Support Warning
WebGPU is currently only supported on Chrome starting with version 113, and only on desktop. If they don't work on your configuration, you can check the WebGL2 examples
here.
embedded_asset.rs:
use bevy::asset::{embedded_asset, io::AssetSourceId, AssetPath};
use bevy::prelude::*;
use std::path::Path;
fn main() {
App::new()
.add_plugins((DefaultPlugins, EmbeddedAssetPlugin))
.add_systems(Startup, setup)
.run();
}
struct EmbeddedAssetPlugin;
impl Plugin for EmbeddedAssetPlugin {
fn build(&self, app: &mut App) {
let omit_prefix = "examples/asset";
embedded_asset!(app, omit_prefix, "files/bevy_pixel_light.png");
}
}
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.spawn(Camera2dBundle::default());
let crate_name = "embedded_asset";
let path = Path::new(crate_name).join("files/bevy_pixel_light.png");
let source = AssetSourceId::from("embedded");
let asset_path = AssetPath::from_path(&path).with_source(source);
assert_eq!(
asset_path,
"embedded://embedded_asset/files/bevy_pixel_light.png".into()
);
commands.spawn(SpriteBundle {
texture: asset_server.load(asset_path),
..default()
});
}