/bevy-skills:bevy-custom-assetsfrom bevy-skills
Implements custom AssetLoader for Bevy 0.20, covering TypePath derivation, dependency loading via LoadContext, Reader usage, and seekable reader patterns.
Ships in bevy-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
is_srgb = false) or by erased type.reader.seekable()), or writing your own Reader.MyLoader: TypePath is not implemented", "no method loader", "missing trait item seekable".use bevy::asset::io::Reader;
use bevy::asset::{Asset, AssetApp, AssetLoader, LoadContext};
use bevy::image::ImageLoaderSettings;
use bevy::prelude::*;
use bevy::reflect::TypePath;
#[derive(Asset, TypePath, Debug)]
pub struct LevelDef {
pub name: String,
pub gravity: f32,
#[dependency] // counted toward `LoadedWithDependencies`
pub thumbnail: Handle<Image>,
#[dependency]
pub normal_map: Handle<Image>,
}
#[derive(TypePath)] // required on the loader itself since 0.18
pub struct LevelLoader;
impl AssetLoader for LevelLoader {
type Asset = LevelDef;
type Settings = ();
type Error = BevyError; // any `Error` converts via `?`
async fn load(
&self,
reader: &mut dyn Reader,
_settings: &Self::Settings,
load_context: &mut LoadContext<'_>,
) -> Result<Self::Asset, Self::Error> {
let mut bytes = Vec::new();
reader.read_to_end(&mut bytes).await?;
let text = String::from_utf8(bytes)?;
let mut level = LevelDef {
name: String::new(),
gravity: 9.81,
thumbnail: Handle::default(),
normal_map: Handle::default(),
};
for line in text.lines() {
let Some((key, value)) = line.split_once('=') else { continue };
match key.trim() {
"name" => level.name = value.trim().to_owned(),
"gravity" => level.gravity = value.trim().parse()?,
// Dependencies go through `LoadContext`, never `AssetServer`.
"thumbnail" => level.thumbnail = load_context.load(value.trim().to_owned()),
// 0.19+: settings, type erasure, untyped loads use `load_builder()`.
"normal_map" => {
level.normal_map = load_context
.load_builder()
.with_settings(|s: &mut ImageLoaderSettings| s.is_srgb = false)
.load(value.trim().to_owned());
}
_ => {}
}
}
Ok(level)
}
fn extensions(&self) -> &[&str] {
&["level"]
}
}
pub struct LevelLoaderPlugin;
impl Plugin for LevelLoaderPlugin {
fn build(&self, app: &mut App) {
app.init_asset::<LevelDef>()
.register_asset_loader(LevelLoader);
}
}
use bevy::asset::io::{Reader, ReaderNotSeekableError};
use bevy::asset::AsyncSeekExt;
async fn read_footer(reader: &mut dyn Reader) -> std::io::Result<[u8; 8]> {
let mut footer = [0u8; 8];
match reader.seekable() {
Ok(seekable) => {
// `SeekableReader: Reader + AsyncSeek`; `AsyncSeekExt` is re-exported by bevy::asset.
seekable.seek(std::io::SeekFrom::End(-8)).await?;
let mut buf = Vec::new();
seekable.read_to_end(&mut buf).await?;
footer.copy_from_slice(&buf);
}
Err(ReaderNotSeekableError) => {
// e.g. HTTP source: stream the whole file instead.
let mut buf = Vec::new();
reader.read_to_end(&mut buf).await?;
footer.copy_from_slice(&buf[buf.len() - 8..]);
}
}
Ok(footer)
}
Reader yourself (0.19+ shape)use bevy::asset::io::{Reader, ReaderNotSeekableError, SeekableReader};
use bevy::tasks::futures_lite::io::Cursor;
use bevy::tasks::futures_lite::{AsyncRead, AsyncSeek};
use std::pin::Pin;
use std::task::{Context, Poll};
pub struct MemReader(Cursor<Vec<u8>>);
impl AsyncRead for MemReader {
fn poll_read(mut self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut [u8])
-> Poll<std::io::Result<usize>> {
Pin::new(&mut self.0).poll_read(cx, buf)
}
}
impl AsyncSeek for MemReader {
fn poll_seek(mut self: Pin<&mut Self>, cx: &mut Context<'_>, pos: std::io::SeekFrom)
-> Poll<std::io::Result<u64>> {
Pin::new(&mut self.0).poll_seek(cx, pos)
}
}
impl Reader for MemReader {
// 0.19+: required. `AsyncSeekForward` is gone.
fn seekable(&mut self) -> Result<&mut dyn SeekableReader, ReaderNotSeekableError> {
Ok(self) // return `Err(ReaderNotSeekableError)` if you cannot seek
}
}
LoadDirectError::LoadError { error } is Box<AssetLoadError> and AssetLoadError::RequestedHandleTypeMismatch wraps a Box<RequestedHandleTypeMismatchError>. Match through the box.NestedLoadBuilder immediate loads are async: load_value(path).await, load_erased_value(type_id, path), load_untyped_value(path), load_value_from_reader(path, reader). They return Result<LoadedAsset<A>, LoadDirectError>.UntypedHandle::meta_transform() is deleted. Settings travel only through with_settings closures.LoadContext::loader() is load_builder() and NestedLoader is NestedLoadBuilder. Stale output: ctx.loader().with_settings(..).load(p). Now: ctx.load_builder().with_settings(..).load(p). with_dynamic_type(id).load(p) → load_erased(id, p); with_unknown_type().load(p) → load_untyped(p); immediate().load(p) → load_value(p).await.Reader impls must implement seekable. AsyncSeekForward is deleted; implement AsyncSeek (poll_seek) and return Ok(self). Callers of the old trait use AsyncSeekExt::seek(SeekFrom::Current(n)).AssetSaver::save gained a lifetime and a path: asset: SavedAsset<'_, '_, A>, settings: &S, asset_path: AssetPath<'_>.bevy-ecs-components).#[derive(TypePath)] on the loader struct, not only the asset. AssetLoader: TypePath + Send + Sync + 'static.LoadContext::asset_bytes() is gone. Use reader.read_to_end(&mut bytes).await? or load_context.read_asset_bytes(path).await? for a sibling file.LoadContext. asset_server.load inside a loader does not register the dependency, so LoadedWithDependencies fires early. Mark handle fields #[dependency] so #[derive(Asset)] visits them.type Error only needs Into<BevyError>. BevyError itself is the shortest choice; thiserror enums still work.load. The executor is Bevy's; use bevy::tasks::futures_lite or AsyncComputeTaskPool.Settings must be Default + Serialize + DeserializeOwned to round-trip through .meta files."level.ron" matches foo.level.ron, not foo.ron.AsyncReadExt next to dyn Reader. Both traits define read_to_end; the call becomes ambiguous. Reader::read_to_end is inherent to the trait.bevy-assets — using the Handle<LevelDef> once loaded, load_builder on AssetServer.bevy-voxel-data — RON-driven asset patterns.bevy-migration-0-18-to-0-19 — loader() → load_builder(), Reader::seekable.bevy-migration-0-19-to-0-20 — boxed error variants.What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub chrisgliddon/bevy-skills --plugin bevy-skills32 skills in this plugin
/bevyUse when starting any Bevy task, choosing between Update and FixedUpdate, picking Cargo feature flags, or recalling which sibling skill covers ECS, assets, rendering, UI, or migration. Routes to the right Bevy 0.20 skill and pins the engine version for downstream snippets./bevy-a11yUse when designing or auditing high-standard video-game accessibility in Bevy 0.20, integrating screen readers and focus navigation, supporting adaptive controllers and complete remapping, implementing captions or audio description, checking contrast and motion safety, or building disabled-player test evidence./bevy-animationUse when wiring `AnimationPlayer` + `AnimationGraphHandle`, building an `AnimationGraph` from glTF clips, blending state-driven animations with `AnimationTransitions::play`, isolating body parts with `AnimationMask`, firing gameplay sync via `#[derive(AnimationEvent)]` + `On<E>` observers, tweening with `AnimatableCurve` / `EaseFunction` / `CubicSegment::new_bezier_easing` from `bevy::curve`, or applying the 12 Basic Principles of Animation to 3D characters in Bevy 0.20./bevy-assetsUse when loading with `AssetServer::load` or `AssetServer::load_builder().with_settings(..)`, holding a `Handle<T>`, spawning a glTF scene with `WorldAssetRoot` (`Handle<WorldAsset>`), mutating through `Assets::get_mut` / `AssetMut`, polling `LoadState::is_loaded`, resolving an `AssetPath`, or replacing `AssetId::invalid()` with `Option<AssetId<T>>` in Bevy 0.20./bevy-audioUse when implementing audio in Bevy 0.20 with `AudioPlayer`, `PlaybackSettings`, `AudioSink` or `SpatialAudioSink`, spatial listeners, application mix groups, ambience/music transitions, asset lifetime, browser gesture restrictions, or choosing built-in audio versus `bevy_seedling 0.8`./bevy-camerasUse when spawning `Camera3d` or `Camera2d`, choosing a `Projection`, rendering to an image with the `RenderTarget` component, adding `Hdr` / `Tonemapping::Linear` / `ScreenSpaceTransmission` to a camera, wiring `FreeCamera`, `PanCamera` or the new `PanOrbitCamera` from `bevy::camera_controller`, ordering views with `Camera::order`, or setting a per-camera `AmbientLight` in Bevy 0.20.Other plugins' skills for the same job