{"record":{"id":"24c421b00e39748e","repo":"bevyengine/bevy","slug":"asset-derive-currently-doesn-t-work-on-unions","errorCode":null,"errorMessage":"Asset derive currently doesn't work on unions","messagePattern":"Asset derive currently doesn't work on unions","errorType":"validation","errorClass":"syn::Error","httpStatus":null,"severity":"error","filePath":"crates/bevy_asset/macros/src/lib.rs","lineNumber":89,"sourceCode":"            let cases = cases.map(|variant| {\n                let ident = &variant.ident;\n                let field_members = variant\n                    .fields\n                    .iter()\n                    .enumerate()\n                    .filter(|(_, f)| field_has_dep(f))\n                    .map(|(i, field)| as_member(field.ident.as_ref(), i));\n                let field_locals = field_members.clone().map(|m| format_ident!(\"__self_{}\", m));\n                let field_visitors = field_locals.clone().map(|i| visit_dep(quote!(#i)));\n                quote!(Self::#ident {#(#field_members: #field_locals,)* ..} => {\n                    #(#field_visitors)*\n                })\n            });\n\n            any_case_required.then(|| quote!(match self { #(#cases)*, _ => {} }))\n        }\n        Data::Union(_) => {\n            return Err(syn::Error::new(\n                Span::call_site().into(),\n                \"Asset derive currently doesn't work on unions\",\n            ));\n        }\n    };\n\n    // prevent unused variable warning in case there are no dependencies\n    let visit = if body.is_none() {\n        quote! { _visit }\n    } else {\n        quote! { visit }\n    };\n\n    Ok(quote! {\n        impl #impl_generics #bevy_asset_path::VisitAssetDependencies for #struct_name #type_generics #where_clause {\n            fn visit_dependencies(&self, #visit: &mut impl ::core::ops::FnMut(#bevy_asset_path::UntypedAssetId)) {\n                #body\n            }","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/bevyengine/bevy/blob/396ca727080776bd313bb892423b7d94e03b81b4/crates/bevy_asset/macros/src/lib.rs#L71-L107","documentation":"Compile-time panic from the Asset derive macro machinery (derive_dependency_visitor_internal): the derive was applied to a union. The generated dependency-visitor code only supports structs and enums, so unions are rejected outright by the proc macro.","triggerScenarios":"Thrown at crates/bevy_asset/macros/src/lib.rs:89 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Replace the union with a struct or enum so the Asset derive can generate code","Implement the Asset trait (and any dependency visitor) manually for the union type if unions are truly required"],"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-14T05:17:10.506Z"}