bevy_elf
Load and resolve assets that reference other assets by name, in Bevy.
Hand-written asset types use Handle<T>, which isn't serializable. bevy_elf generates a
serializable "Def" counterpart of your asset struct — using plain strings in place of
Handles — and a FromDef implementation that converts the Def back into your runtime type,
resolving each string into a Handle along the way.
// water_animation.ron
(
frames: [1, 2, 3],
frame_duration: (secs: 0, nanos: 128000000),
spritesheet: "water",
)
use *;
use ;
use Duration;
The derive macro generates the Def struct, its Deserialize impl, and the resolution logic
that turns "water" into Handle<Spritesheet> by loading spritesheets/water.ron. Register
the loader with the RonAssetPlugin:
app.add_plugins;
Why
Bevy assets that reference other assets naturally want to hold a Handle<T>, but Handle
isn't something you can put in a .ron/.toml/.json file — there's nothing to point at
until the asset is loaded. The usual workaround is writing two versions of every asset type by
hand: a serializable "spec" version with string IDs, and a runtime version with Handles, plus
the boilerplate to convert between them. bevy_elf generates that boilerplate for you.
Features
| Feature | Default | Adds |
|---|---|---|
macros |
✅ | The FromDef derive macro and asset_spec attribute (via bevy_elf_macros) |
math |
✅ | FromDef impls for bevy_math types (Vec2, Vec3, Quat, Rect, ...) |
image |
❌ | FromDef impl for bevy_image::TextureAtlasLayout |
Without macros, you can still implement FromDef/FromDefWithResolver by hand for full
control over the conversion.
More examples
Implicit fields, omitting empty def files, and resolving foreign types (types you don't own,
like Handle<Image>) are covered in the crate documentation.
Bevy compatibility
| bevy | bevy_elf |
|---|---|
| 0.19 | 0.1 |
License
Dual-licensed under either
- MIT License (LICENSE-MIT)
- Apache License, Version 2.0 (LICENSE-APACHE)
at your option.