{"record":{"id":"fca4163a0cc2b48a","repo":"bevyengine/bevy","slug":"type-path-should-have-reflect-component-or","errorCode":null,"errorMessage":"`{type_path}` should have #[reflect(Component)] or #[reflect(Bundle)]","messagePattern":"`(.+?)` should have #\\[reflect\\(Component\\)\\] or #\\[reflect\\(Bundle\\)\\]","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/bevy_ecs/src/reflect/entity_commands.rs","lineNumber":376,"sourceCode":"fn insert_reflect_with_registry_ref(\n    entity: &mut EntityWorldMut,\n    type_registry: &TypeRegistry,\n    component: Box<dyn PartialReflect>,\n) {\n    let type_info = component\n        .get_represented_type_info()\n        .expect(\"component should represent a type.\");\n    let type_path = type_info.type_path();\n    let Some(type_registration) = type_registry.get(type_info.type_id()) else {\n        panic!(\"`{type_path}` should be registered in type registry via `App::register_type<{type_path}>`\");\n    };\n\n    if let Some(reflect_component) = type_registration.data::<ReflectComponent>() {\n        reflect_component.insert(entity, component.as_partial_reflect(), type_registry);\n    } else if let Some(reflect_bundle) = type_registration.data::<ReflectBundle>() {\n        reflect_bundle.insert(entity, component.as_partial_reflect(), type_registry);\n    } else {\n        panic!(\"`{type_path}` should have #[reflect(Component)] or #[reflect(Bundle)]\");\n    }\n}\n\n/// Helper function to remove a reflect component or bundle from a given entity\nfn remove_reflect_with_registry_ref(\n    entity: &mut EntityWorldMut,\n    type_registry: &TypeRegistry,\n    component_type_path: Cow<'static, str>,\n) {\n    let Some(type_registration) = type_registry.get_with_type_path(&component_type_path) else {\n        return;\n    };\n    if let Some(reflect_component) = type_registration.data::<ReflectComponent>() {\n        reflect_component.remove(entity);\n    } else if let Some(reflect_bundle) = type_registration.data::<ReflectBundle>() {\n        reflect_bundle.remove(entity);\n    }\n}","sourceCodeStart":358,"sourceCodeEnd":394,"githubUrl":"https://github.com/bevyengine/bevy/blob/396ca727080776bd313bb892423b7d94e03b81b4/crates/bevy_ecs/src/reflect/entity_commands.rs#L358-L394","documentation":"The type IS registered in the `TypeRegistry`, but its registration carries neither `ReflectComponent` nor `ReflectBundle` type data, so Bevy cannot treat it as a component to insert. Those data entries are produced by the `#[reflect(Component)]` (or `#[reflect(Bundle)]`) attribute on a `Reflect`-derived type; without them, `insert_reflect` panics at the final else-branch.","triggerScenarios":"Calling `insert_reflect` on a type that derives `Reflect` (and is registered) but omits `#[reflect(Component)]`, or on a bundle type without `#[reflect(Bundle)]`.","commonSituations":"Adding `Reflect` to a component for serialization and forgetting the component-specific attribute; registering a plain data type (no `Component` derive) and then trying to insert it reflectively; upgrading Bevy versions where the required attribute set changed.","solutions":["Add `#[reflect(Component)]` to the component (it must also `#[derive(Component)]`) so registration includes ReflectComponent data","For bundle types, add `#[reflect(Bundle)]`","If you cannot edit the type, attach the data manually: `app.register_type_data::<T, ReflectComponent>()` when `T: Component`"],"exampleFix":"// before\n#[derive(Component, Reflect)]\nstruct Mass(f32);\napp.register_type::<Mass>();\nentity.insert_reflect(Box::new(Mass(1.0))); // panics: no #[reflect(Component)]\n\n// after\n#[derive(Component, Reflect)]\n#[reflect(Component)]\nstruct Mass(f32);","handlingStrategy":"validation","validationCode":"// Verify the registration carries component data before inserting\nlet registry = app.world().resource::<AppTypeRegistry>().read();\nlet has_data = registry\n    .get(TypeId::of::<MyComponent>())\n    .map(|r| r.data::<ReflectComponent>().is_some())\n    .unwrap_or(false);\nassert!(has_data, \"missing #[reflect(Component)]\");","typeGuard":"fn has_reflect_component_data<T: Reflect + 'static>(registry: &TypeRegistry) -> bool {\n    registry.get(TypeId::of::<T>())\n        .map(|r| r.data::<ReflectComponent>().is_some())\n        .unwrap_or(false)\n}","tryCatchPattern":null,"preventionTips":["Pair every #[derive(Component, Reflect)] with #[reflect(Component)] by convention/lint","For foreign types, call app.register_type_data::<T, ReflectComponent>() explicitly","Add a smoke test that inserts a reflected instance of each editor-mutated type"],"tags":["bevy","reflection","type-registry","component","panic"],"backgroundTag":"missing-reflect-type-data","analyzedSha":"396ca727080776bd313bb892423b7d94e03b81b4","analyzedAt":"2026-08-20T16:12:39.808Z","schemaVersion":2},"datasetVersion":"2026-08-22T04:17:13.399Z"}