bevyengine/bevy · error · syn::Error
reflection not supported for unions
Error message
reflection not supported for unions
What it means
Compile-time error raised in ReflectDeriveInput::from_input: #[derive(Reflect)] was applied to a union, which reflection does not support — only structs, enums, tuple structs, and unit structs can be reflected.
Source
Thrown at crates/bevy_reflect/derive/src/derive_data.rs:317
let reflect_struct = ReflectStruct {
meta,
serialization_data,
fields,
};
match data.fields {
Fields::Named(..) => Ok(Self::Struct(reflect_struct)),
Fields::Unnamed(..) => Ok(Self::TupleStruct(reflect_struct)),
Fields::Unit => Ok(Self::UnitStruct(reflect_struct)),
}
}
Data::Enum(data) => {
let variants = Self::collect_enum_variants(&data.variants)?;
let reflect_enum = ReflectEnum { meta, variants };
Ok(Self::Enum(reflect_enum))
}
Data::Union(..) => Err(syn::Error::new(
input.span(),
"reflection not supported for unions",
)),
}
}
/// Set the remote type for this derived type.
///
/// # Panics
///
/// Panics when called on [`ReflectDerive::Opaque`].
pub fn set_remote(&mut self, remote_ty: Option<RemoteType<'a>>) {
match self {
Self::Struct(data) | Self::TupleStruct(data) | Self::UnitStruct(data) => {
data.meta.remote_ty = remote_ty;
}
Self::Enum(data) => {
data.meta.remote_ty = remote_ty;View on GitHub (pinned to 396ca72708)
Solutions
- Replace the union with a struct or enum
- Implement reflection manually for the union's wrapper type
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/bevy_reflect/derive/src/derive_data.rs:317 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/05a818431f92f3fa.
Report an issue: GitHub.