bevyengine/bevy · error · GetComponentReflectError::MissingAppTypeRegistry

The `World` was missing the `AppTypeRegistry` resource

Error message

The `World` was missing the `AppTypeRegistry` resource

What it means

GetComponentReflectError::MissingAppTypeRegistry is returned by World::get_reflect / get_reflect_mut when the World has no AppTypeRegistry resource, which is the shared bevy_reflect TypeRegistry that reflective component access depends on. bevy_app inserts this resource when an App is built, so hitting this error almost always means you are using a bare World (or stripped one) that never went through App bootstrap.

Source

Thrown at crates/bevy_ecs/src/world/reflect.rs:239

    #[error("No `ComponentId` corresponding to {0:?} found (did you call App::register_type()?)")]
    NoCorrespondingComponentId(TypeId),

    /// The given [`Entity`] does not have a [`Component`] corresponding to the given [`TypeId`].
    #[error("The given `Entity` {entity} does not have a `{component_name:?}` component ({component_id:?}, which corresponds to {type_id:?})")]
    EntityDoesNotHaveComponent {
        /// The given [`Entity`].
        entity: Entity,
        /// The given [`TypeId`].
        type_id: TypeId,
        /// The [`ComponentId`] corresponding to the given [`TypeId`].
        component_id: ComponentId,
        /// The name corresponding to the [`Component`] with the given [`TypeId`], or `None`
        /// if not available.
        component_name: Option<DebugName>,
    },

    /// The [`World`] was missing the [`AppTypeRegistry`] resource.
    #[error("The `World` was missing the `AppTypeRegistry` resource")]
    MissingAppTypeRegistry,

    /// The [`World`]'s [`TypeRegistry`] did not contain [`TypeData`] for [`ReflectFromPtr`] for the given [`TypeId`].
    ///
    /// This is usually handled by calling [`App::register_type`] for the type corresponding to
    /// the given [`TypeId`].
    ///
    /// See the documentation for [`bevy_reflect`] for more information.
    ///
    /// [`TypeData`]: bevy_reflect::TypeData
    /// [`TypeRegistry`]: bevy_reflect::TypeRegistry
    /// [`ReflectFromPtr`]: bevy_reflect::ReflectFromPtr
    /// [`App::register_type`]: ../../../bevy_app/struct.App.html#method.register_type
    #[error("The `World`'s `TypeRegistry` did not contain `TypeData` for `ReflectFromPtr` for the given {0:?} (did you call `App::register_type()`?)")]
    MissingReflectFromPtrTypeData(TypeId),
}

#[cfg(test)]

View on GitHub (pinned to 396ca72708)

Solutions

  1. Insert the registry into the bare World: world.insert_resource(AppTypeRegistry::default()) (then register the types you need, e.g. registry.write().register::<T>()).
  2. Prefer building a minimal App in tests (App::new() plus the needed plugins) so bootstrap resources exist.
  3. If the World was cleared, re-insert AppTypeRegistry after clear_resources/clear_all.
  4. Guard with world.get_resource::<AppTypeRegistry>().is_some() before doing reflective work and skip/fail softly.

Example fix

// before
let mut world = World::new();
let c = world.get_reflect(entity, TypeId::of::<Health>())?; // MissingAppTypeRegistry

// after
use bevy_ecs::reflect::AppTypeRegistry;
let mut world = World::new();
let registry = AppTypeRegistry::default();
registry.write().register::<Health>();
world.insert_resource(registry);
let c = world.get_reflect(entity, TypeId::of::<Health>())?;
Defensive patterns

Strategy: validation

Validate before calling

if world.get_resource::<AppTypeRegistry>().is_none() {
    let registry = AppTypeRegistry::default();
    registry.write().register::<T>();
    world.insert_resource(registry);
}

Try / catch

match world.get_reflect(entity, TypeId::of::<T>()) {
    Err(GetComponentReflectError::MissingAppTypeRegistry) => {
        // initialize registry or fall back to typed access
    }
    other => { /* ... */ }
}

Prevention

When it happens

Trigger: Calling world.get_reflect / get_reflect_mut on a manually constructed World (unit tests, benchmarks, tooling) without inserting AppTypeRegistry; a World cleared with clear_resources()/clear_all() that dropped the registry; a sub-world created manually for extraction that is missing the registry resource.

Common situations: Unit tests that do `let mut world = World::new();` and then exercise reflection helpers; procedural tooling that spawns isolated Worlds; refactors that moved reflective code from an App-driven system into a raw-World context.

Related errors


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