{"record":{"id":"e97615b1c396b511","repo":"bevyengine/bevy","slug":"derive-derive-expected-named-or-unnamed-struct","errorCode":null,"errorMessage":"{derive} derive expected named or unnamed struct, found unit struct.","messagePattern":"(.+?) derive expected named or unnamed struct, found unit struct\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/bevy_ecs/macro_logic/src/component.rs","lineNumber":821,"sourceCode":"                .attrs\n                .iter()\n                .any(|attr| attr.path().is_ident(RELATIONSHIP))\n        }).ok_or(syn::Error::new(\n            span,\n            format!(\"{derive} derive expected named structs with a single field or with a field annotated with #[relationship].\")\n        )),\n        Fields::Unnamed(fields) if fields.unnamed.len() == 1 => Ok(fields.unnamed.first().unwrap()),\n        Fields::Unnamed(fields) => fields.unnamed.iter().find(|field| {\n                field\n                    .attrs\n                    .iter()\n                    .any(|attr| attr.path().is_ident(RELATIONSHIP))\n            })\n            .ok_or(syn::Error::new(\n                span,\n                format!(\"{derive} derive expected unnamed structs with one field or with a field annotated with #[relationship].\"),\n            )),\n        Fields::Unit => Err(syn::Error::new(\n            span,\n            format!(\"{derive} derive expected named or unnamed struct, found unit struct.\"),\n        )),\n    }\n}\n","sourceCodeStart":803,"sourceCodeEnd":827,"githubUrl":"https://github.com/bevyengine/bevy/blob/396ca727080776bd313bb892423b7d94e03b81b4/crates/bevy_ecs/macro_logic/src/component.rs#L803-L827","documentation":"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.","triggerScenarios":"Thrown at crates/bevy_ecs/macro_logic/src/component.rs:821 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Give the struct a field that holds the target Entity, e.g. struct ChildOf(Entity); or struct ChildOf { target: Entity }","Do not derive relationship macros on marker-style unit structs"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"396ca727080776bd313bb892423b7d94e03b81b4","analyzedAt":"2026-08-20T16:12:39.808Z","contentChangedAt":"2026-08-20T16:12:39.808Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}