bevyengine/bevy · error

attempted to call `TypeRegistry::register_type_data` for typ

Error message

attempted to call `TypeRegistry::register_type_data` for type `{T}` with data `{D}` without registering `{T}` first

What it means

Panic in TypeRegistry::register_type_data: type T (the data's target) was not registered in the registry before adding type data D for it. Call register::<T>() (or register_type_data with the derive-included data) before adding extra type data.

Source

Thrown at crates/bevy_reflect/src/type_registry.rs:346

    /// Registers the type data `D` for type `T`.
    ///
    /// Most of the time [`TypeRegistry::register`] can be used instead to register a type you derived [`Reflect`] for.
    /// However, in cases where you want to add a piece of type data that was not included in the list of `#[reflect(...)]` type data in the derive,
    /// or where the type is generic and cannot register the type data unconditionally without knowing the specific type parameters,
    /// this method can be used to insert additional type data.
    ///
    /// # Example
    /// ```
    /// use bevy_reflect::{TypeRegistry, ReflectSerialize, ReflectDeserialize};
    ///
    /// let mut type_registry = TypeRegistry::default();
    /// type_registry.register::<Option<String>>();
    /// type_registry.register_type_data::<Option<String>, ReflectSerialize>();
    /// type_registry.register_type_data::<Option<String>, ReflectDeserialize>();
    /// ```
    pub fn register_type_data<T: Reflect + TypePath, D: CreateTypeData<T>>(&mut self) {
        let data = self.get_mut(TypeId::of::<T>()).unwrap_or_else(|| {
            panic!(
                "attempted to call `TypeRegistry::register_type_data` for type `{T}` with data `{D}` without registering `{T}` first",
                T = T::type_path(),
                D = core::any::type_name::<D>(),
            )
        });
        data.insert(D::create_type_data(()));
    }

    /// Registers the type data `D` with parameter `P` for type `T`.
    ///
    /// Most of the time [`TypeRegistry::register`] can be used instead to register a type you derived [`Reflect`] for.
    /// However, in cases where you want to add a piece of type data that was not included in the list of `#[reflect(...)]` type data in the derive,
    /// or where the type is generic and cannot register the type data unconditionally without knowing the specific type parameters,
    /// this method can be used to insert additional type data.
    ///
    /// If no parameters are needed for the type data or the type data does not accept parameters,
    /// then [`TypeRegistry::register_type_data`] may be used instead.
    pub fn register_type_data_with<T: Reflect + TypePath, D: CreateTypeData<T, P>, P>(

View on GitHub (pinned to 396ca72708)

Solutions

  1. Call registry.register::<T>() before register_type_data::<T, D>()
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/bevy_reflect/src/type_registry.rs:346 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/65dc3fb7d8470897. Report an issue: GitHub.