Macros Overview
mevy provides three core macro families, each solving a different pain point in Bevy development. They’re designed to work together — use ui!{} to build UI bundles, code!{} for inline values, and entity!{} to spawn and manage entities.
Quick Reference
| Macro | Purpose | Use when you need… |
|---|---|---|
code!{} | Inline value construction | Hex colors, Val, UiRect without function calls |
ui!{} | CSS-like UI bundles | Multiple UI components without boilerplate |
entity!{} | Entity spawning & modification | Hierarchies, queries, and observers in one expression |
When to Use Which
- Just a color or value? →
code!{} - A styled UI panel? →
ui!{} - A complete entity with children? →
entity!{} - All three together? → Use them together.
entity!{}nestsui!{}naturally, andcode!{}works inside both.
How They Work Together
entity!{
<world>
// ui!{} creates a bundle of UI components
ui!((
size: 100px 100px;
background: #ff0000;
));
// code!{} creates inline values
BackgroundColor(code!{#00ff00});
// Nested children with named entities
[child][
ui!(( size: 50px 50px; ));
.observe(on_click);
]
}
Troubleshooting
“Missing bevy version” compile error
You need to specify the Bevy version feature in Cargo.toml:
mevy = { version = "0.3", features = ["0.18"] }
See Installation for the full list of supported versions.
Experimental features unexpectedly enabled
mevy_ecs has experimental as a default feature. To disable it:
mevy_ecs = { version = "0.2.4", default-features = false }
Navigation
- entity!{} — Entity spawning & modification
- ui!{} — CSS-like UI notation
- code!{} — Code replacement macro
- Experimental Helpers —
gere!,geco!,cen!,den!,wen!