bevyengine/bevy · error
{derive} derive expected unnamed structs with one field or w
Error message
{derive} derive expected unnamed structs with one field or with a field annotated with #[relationship]. What it means
Compile error from relationship_field: the derive was applied to a tuple (unnamed) struct with multiple fields and none is marked #[relationship], so the helper cannot pick the relationship field. This branch mirrors the named-struct guard for Fields::Unnamed.
Source
Thrown at crates/bevy_ecs/macro_logic/src/component.rs:817
match fields {
Fields::Named(fields) if fields.named.len() == 1 => Ok(fields.named.first().unwrap()),
Fields::Named(fields) => fields.named.iter().find(|field| {
field
.attrs
.iter()
.any(|attr| attr.path().is_ident(RELATIONSHIP))
}).ok_or(syn::Error::new(
span,
format!("{derive} derive expected named structs with a single field or with a field annotated with #[relationship].")
)),
Fields::Unnamed(fields) if fields.unnamed.len() == 1 => Ok(fields.unnamed.first().unwrap()),
Fields::Unnamed(fields) => fields.unnamed.iter().find(|field| {
field
.attrs
.iter()
.any(|attr| attr.path().is_ident(RELATIONSHIP))
})
.ok_or(syn::Error::new(
span,
format!("{derive} derive expected unnamed structs with one field or with a field annotated with #[relationship]."),
)),
Fields::Unit => Err(syn::Error::new(
span,
format!("{derive} derive expected named or unnamed struct, found unit struct."),
)),
}
}
View on GitHub (pinned to 396ca72708)
Solutions
- Mark the intended field with #[relationship]: struct X(#[relationship] Entity, Foo);
- Shrink the tuple struct to a single field such as struct ChildOf(Entity);
- Use a named struct with one field instead
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/bevy_ecs/macro_logic/src/component.rs:817 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/2edb926e84993929.
Report an issue: GitHub.