bevyengine/bevy · error

{derive} derive expected named or unnamed struct, found unit

Error message

{derive} derive expected named or unnamed struct, found unit struct.

What it means

Compile error from relationship_field: the derive was applied to a unit struct (no fields at all), which cannot store the Entity that a relationship needs. The match on Fields fell through both Named and Unnamed arms into this unit-struct guard.

Source

Thrown at crates/bevy_ecs/macro_logic/src/component.rs:821

                .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

  1. Give the struct a field that holds the target Entity, e.g. struct ChildOf(Entity); or struct ChildOf { target: Entity }
  2. Do not derive relationship macros on marker-style unit structs
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/bevy_ecs/macro_logic/src/component.rs:821 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/e97615b1c396b511. Report an issue: GitHub.