bevyengine/bevy · error · syn::Error
EntityEvent derive does not work on unit structs. Your type
Error message
EntityEvent derive does not work on unit structs. Your type must have a field to store the `Entity` target, such as `Attack(Entity)` or `Attack { entity: Entity }`. What it means
Compile error from get_event_target_field: the struct is a unit struct with zero fields, so there is nowhere to store the Entity target required by EntityEvent. This is the final match arm guarding Fields::Unit, with a hint message suggesting field shapes that work.
Source
Thrown at crates/bevy_ecs/macros/src/event.rs:204
fields.span(),
"EntityEvent derive expected a field name 'entity' or a field annotated with #[event_target]."
)),
Fields::Unnamed(fields) if fields.unnamed.len() == 1 => Ok(Member::Unnamed(Index::from(0))),
Fields::Unnamed(fields) => fields.unnamed.iter().enumerate().find_map(|(index, field)| {
if field
.attrs
.iter()
.any(|attr| attr.path().is_ident(EVENT_TARGET)) {
Some(Member::Unnamed(Index::from(index)))
} else {
None
}
})
.ok_or(syn::Error::new(
fields.span(),
"EntityEvent derive expected unnamed structs with one field or with a field annotated with #[event_target].",
)),
Fields::Unit => Err(syn::Error::new(
fields.span(),
"EntityEvent derive does not work on unit structs. Your type must have a field to store the `Entity` target, such as `Attack(Entity)` or `Attack { entity: Entity }`.",
)),
}
}
View on GitHub (pinned to 396ca72708)
Solutions
- Add a field to store the target, e.g. struct Attack(Entity); or struct Attack { entity: Entity }
- Use a marker component separately instead of deriving EntityEvent on a unit struct
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/bevy_ecs/macros/src/event.rs:204 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of bevyengine/bevy@396ca72708 (2026-08-20).
Data as JSON: /api/errors/34b124a1356155d1.
Report an issue: GitHub.