bevyengine/bevy · error

Couldn't create an instance of `{name}` using the reflected

Error message

Couldn't create an instance of `{name}` using the reflected `FromReflect`, `Default` or `FromWorld` traits. Are you perhaps missing a `#[reflect(Default)]` or `#[reflect(FromWorld)]`?

What it means

`from_reflect_with_fallback` materializes an instance of `T` so reflected data can be applied onto it (used by `ReflectComponent::from_world`, scene cloning, entity mapping). It tries, in order: the `FromReflect` trait, a reflected `Default`, and a reflected `FromWorld`. If none is available for the type, it panics — Bevy has no way to conjure a starting value to apply the reflection onto.

Source

Thrown at crates/bevy_ecs/src/reflect/mod.rs:140

        // it doesn't need a subsequent `apply` and may fail.
        // If it fails it's ok, we can continue checking `Default` and `FromWorld`.
        let (value, source) = if let Some(value) = registry
            .get_type_data::<ReflectFromReflect>(id)
            .and_then(|reflect_from_reflect| reflect_from_reflect.from_reflect(reflected))
        {
            (value, "FromReflect")
        }
        // Create an instance of `T` using either the reflected `Default` or `FromWorld`.
        else if let Some(reflect_default) = registry.get_type_data::<ReflectDefault>(id) {
            let mut value = reflect_default.default();
            value.apply(reflected);
            (value, "Default")
        } else if let Some(reflect_from_world) = registry.get_type_data::<ReflectFromWorld>(id) {
            let mut value = reflect_from_world.from_world(world);
            value.apply(reflected);
            (value, "FromWorld")
        } else {
            panic!(
                "Couldn't create an instance of `{name}` using the reflected `FromReflect`, \
                `Default` or `FromWorld` traits. Are you perhaps missing a `#[reflect(Default)]` \
                or `#[reflect(FromWorld)]`?",
            );
        };
        assert_eq!(
            value.as_any().type_id(),
            id,
            "The registration for the reflected `{source}` trait for the type `{name}` produced \
            a value of a different type",
        );
        value
    }
    *type_erased(
        reflected,
        world,
        registry,
        TypeId::of::<T>(),

View on GitHub (pinned to 396ca72708)

Solutions

  1. Derive `FromReflect` on the component (`#[derive(Component, Reflect, FromReflect)]`) — the preferred fix
  2. Or implement `Default` and register it: add `#[reflect(Default)]`
  3. Or implement `FromWorld` and add `#[reflect(FromWorld)]` for world-aware construction

Example fix

// before
#[derive(Component, Reflect)]
#[reflect(Component)]
struct Inventory { items: Vec<Item> } // no Default, no FromReflect

// after
#[derive(Component, Reflect, FromReflect)]
#[reflect(Component)]
struct Inventory { items: Vec<Item> }
Defensive patterns

Strategy: validation

Validate before calling

// Verify the type can be materialized before scene spawn / from_world use
let registry = app.world().resource::<AppTypeRegistry>().read();
let constructible = registry
    .get(TypeId::of::<MyComponent>())
    .map(|r| r.contains::<ReflectDefault>() || r.contains::<ReflectFromWorld>())
    .unwrap_or(false) || impls_from_reflect_marker; // track FromReflect statically per type
assert!(constructible, "derive FromReflect or register Default/FromWorld");

Type guard

fn constructible_via_reflection<T: FromReflect>(_: Option<T>) -> bool { true } // prefer static bounds

Prevention

When it happens

Trigger: Spawning scenes / cloning entities / `ReflectComponent::from_world` for a component that implements neither `FromReflect` nor registered `Default`/`FromWorld` type data — e.g. a component with non-defaultable fields (no `Default` impl) and no `FromReflect` derive.

Common situations: Scene round-trips after adding a new component with required fields; entity-cloning tooling or editor prefab instantiation; upgrading Bevy and hitting the stricter fallback chain for previously `Default`-derived types that dropped the derive.

Related errors


AI-assisted analysis of bevyengine/bevy@396ca72708 (2026-08-20). Data as JSON: /api/errors/d106ae3ee1f070cd. Report an issue: GitHub.