bevyengine/bevy · error · syn::Error
Asset derive currently doesn't work on unions
Error message
Asset derive currently doesn't work on unions
What it means
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.
Source
Thrown at crates/bevy_asset/macros/src/lib.rs:89
let cases = cases.map(|variant| {
let ident = &variant.ident;
let field_members = variant
.fields
.iter()
.enumerate()
.filter(|(_, f)| field_has_dep(f))
.map(|(i, field)| as_member(field.ident.as_ref(), i));
let field_locals = field_members.clone().map(|m| format_ident!("__self_{}", m));
let field_visitors = field_locals.clone().map(|i| visit_dep(quote!(#i)));
quote!(Self::#ident {#(#field_members: #field_locals,)* ..} => {
#(#field_visitors)*
})
});
any_case_required.then(|| quote!(match self { #(#cases)*, _ => {} }))
}
Data::Union(_) => {
return Err(syn::Error::new(
Span::call_site().into(),
"Asset derive currently doesn't work on unions",
));
}
};
// prevent unused variable warning in case there are no dependencies
let visit = if body.is_none() {
quote! { _visit }
} else {
quote! { visit }
};
Ok(quote! {
impl #impl_generics #bevy_asset_path::VisitAssetDependencies for #struct_name #type_generics #where_clause {
fn visit_dependencies(&self, #visit: &mut impl ::core::ops::FnMut(#bevy_asset_path::UntypedAssetId)) {
#body
}View on GitHub (pinned to 396ca72708)
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
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/bevy_asset/macros/src/lib.rs:89 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/24c421b00e39748e.
Report an issue: GitHub.