bevyengine/bevy · error · syn::Error

#[derive(FromWorld)]` does not support unions

Error message

#[derive(FromWorld)]` does not support unions

What it means

Compile error from derive_from_world: the DeriveInput's data is a DataUnion, which the FromWorld derive cannot generate an implementation for. This branch of the struct/enum/union match raises the unsupported-shape sentinel.

Source

Thrown at crates/bevy_ecs/macros/src/lib.rs:912

            match data.variants.iter().find(|variant| {
                variant
                    .attrs
                    .iter()
                    .any(|attr| attr.path().is_ident("from_world"))
            }) {
                Some(variant) => (&variant.fields, Some(&variant.ident)),
                None => {
                    return syn::Error::new(
                        Span::call_site(),
                        "No variant found with the `#[from_world]` attribute",
                    )
                    .into_compile_error()
                    .into();
                }
            }
        }
        Data::Union(_) => {
            return syn::Error::new(
                Span::call_site(),
                "#[derive(FromWorld)]` does not support unions",
            )
            .into_compile_error()
            .into();
        }
    };

    let field_init_expr = quote!(#bevy_ecs_path::world::FromWorld::from_world(world));
    let members = fields.members();

    let field_initializers = match variant_ident {
        Some(variant_ident) => quote!( Self::#variant_ident {
            #(#members: #field_init_expr),*
        }),
        None => quote!( Self {
            #(#members: #field_init_expr),*
        }),

View on GitHub (pinned to 396ca72708)

Solutions

  1. Replace the union with a struct or enum
  2. If per-field construction from World is needed, implement FromWorld manually for a struct
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/bevy_ecs/macros/src/lib.rs:912 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/37973eabaf55eca6. Report an issue: GitHub.