bevy_enum_event
Derive macros that generate Bevy event types from enum variants.
Overview
Transform enum variants into distinct Bevy event structs automatically. Each variant becomes a separate event type in a snake_case module, eliminating boilerplate while preserving type safety.
use *;
use EnumEvent;
// Generates: game_event::Victory, game_event::ScoreChanged, game_event::GameOver
Bevy Compatibility
| Bevy | bevy_enum_event |
|---|---|
| 0.18 | 0.3 |
| 0.17 | 0.2 |
| 0.16 | 0.1 |
Installation
[]
= "0.3"
Macros
EnumEvent- Generates globalEventtypesEnumEntityEvent- Generates entity-targetedEntityEventtypes with optional propagation
EnumEvent
Supports unit, tuple, and named field variants:
use EnumEvent;
Using with Observers
Deref Feature (default)
Single-field variants automatically implement Deref/DerefMut:
For multi-field variants, mark one field with #[enum_event(deref)]:
Disable with default-features = false.
EnumEntityEvent
Entity-targeted events that trigger entity-specific observers.
Requirements
- Named fields only (
{ field: Type }syntax) - Must have
entity: Entityfield or#[enum_event(target)]on a custom field
use *;
use EnumEntityEvent;
// Entity-specific observer
Custom Target Field
Event Propagation
Events can bubble up entity hierarchies:
// Basic propagation (uses ChildOf)
// Auto propagation (always bubbles)
// Custom relationship
Control propagation in observers:
Variant-Level Overrides
Override enum-level settings per variant:
Generics & Lifetimes
Full support for generic parameters and lifetimes:
License
MIT OR Apache-2.0