一键导入
bevy-assets
Reference for loading, managing, and tracking assets in Bevy — AssetServer, handles, loading states, events, custom loaders, and hot reloading.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Reference for loading, managing, and tracking assets in Bevy — AssetServer, handles, loading states, events, custom loaders, and hot reloading.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Reference for Avian physics engine — rigid bodies, colliders, joints, spatial queries, collision events, character controllers, and debug rendering.
Reference for playing and controlling audio in Bevy — AudioPlayer, AudioSink, spatial audio, volume, and playback settings.
Reference for Bevy Scene Notation (BSN) — the bsn! macro for defining inline scenes with components, children, relationships, observers, and dynamic props.
Reference for cameras in Bevy — Camera2d, Camera3d, viewports, projection, render layers, mouse-to-world, and free camera controllers.
Reference for Bevy Commands — spawning/despawning entities, inserting/removing components, custom commands, trait extensions, and testing.
Reference for bevy_enhanced_input — observer-based input manager with actions, contexts, bindings, conditions, modifiers, presets, and mocking.
| name | bevy-assets |
| description | Reference for loading, managing, and tracking assets in Bevy — AssetServer, handles, loading states, events, custom loaders, and hot reloading. |
| metadata | {"crate":"bevy_asset","bevy":"0.19"} |
Assets<T> — stores loaded assets of each typeAssetServer — loads assets from files asynchronouslyfn load(mut image: ResMut<MyImage>, server: Res<AssetServer>) {
image.0 = server.load("images/foo.png");
}
fn spawn(mut meshes: ResMut<Assets<Mesh>>, mut materials: ResMut<Assets<ColorMaterial>>) {
let mesh = meshes.add(Circle::new(50.));
let material = materials.add(Color::BLACK);
commands.spawn((Mesh2d(mesh), MeshMaterial2d(material)));
}
| Extension | Handle |
|---|---|
ttf, otf | Font |
png, jpg, webp, ktx2, bmp, gif, tga, tiff | Image |
mp3, flac, ogg, wav | AudioSource |
gltf, glb | Gltf (use GltfAssetLabel::Scene(0) for a scene) |
scn, scn.ron | DynamicWorld |
let scene: Handle<Scene> = server.load(GltfAssetLabel::Scene(0).from_asset("models/car.glb"));
commands.spawn((SceneRoot(scene), Transform::default()));
use bevy::asset::LoadState;
match server.get_load_state(&handle) {
Some(LoadState::Loaded) => {},
Some(LoadState::Loading) => {},
Some(LoadState::Failed(_)) => {},
_ => {}
}
use bevy::asset::AssetEvent;
fn react(mut events: MessageReader<AssetEvent<Image>>) {
for event in events.read() {
match event {
AssetEvent::Added { id } => {},
AssetEvent::LoadedWithDependencies { id } => {},
AssetEvent::Modified { id } => {},
AssetEvent::Removed { id } => {},
AssetEvent::Unused { id } => {},
}
}
}
use bevy::asset::LoadedFolder;
let _folder: Handle<LoadedFolder> = server.load_folder("models/monkey");
app.register_asset_source("custom", AssetSourceBuilder::platform_default("assets/custom", None));
// Then: server.load("custom://file.png")
#[derive(Asset, TypePath)]
struct TextFile { content: String }
impl AssetLoader for TextFile {
type Asset = TextFile; type Settings = (); type Error = std::io::Error;
async fn load(&self, reader: &mut dyn Reader, _settings: &(), _ctx: &mut LoadContext<'_>) -> Result<Self::Asset, Self::Error> {
let mut content = String::new();
reader.read_to_string(&mut content).await?;
Ok(TextFile { content })
}
fn extensions(&self) -> &[&str] { &["txt"] }
}
// Then: app.init_asset::<TextFile>()
Enable via feature file_watcher in Cargo.toml, or:
app.add_plugins(DefaultPlugins.set(AssetPlugin {
watch_for_changes_override: Some(true),
..default()
}));
Handle<T> creates a strong referenceHandle::Weak does not keep the asset alive