{"record":{"id":"25b7c7ee40c19636","repo":"bevyengine/bevy","slug":"could-not-create-filter-state-please-initialize-a","errorCode":null,"errorMessage":"Could not create filter_state, Please initialize all referenced components before transmuting.","messagePattern":"Could not create filter_state, Please initialize all referenced components before transmuting\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/bevy_ecs/src/query/state.rs","lineNumber":702,"sourceCode":"        world: impl Into<UnsafeWorldCell<'a>>,\n    ) -> QueryState<NewD> {\n        self.transmute_filtered::<NewD, ()>(world.into())\n    }\n\n    /// Creates a new [`QueryState`] with the same underlying [`FilteredAccess`], matched tables and archetypes\n    /// as self but with a new type signature.\n    ///\n    /// Panics if `NewD` or `NewF` require accesses that this query does not have.\n    pub fn transmute_filtered<'a, NewD: SingleEntityQueryData, NewF: QueryFilter>(\n        &self,\n        world: impl Into<UnsafeWorldCell<'a>>,\n    ) -> QueryState<NewD, NewF> {\n        let world = world.into();\n        self.validate_world(world.id());\n\n        let mut component_access = FilteredAccess::default();\n        let mut fetch_state = NewD::get_state(world.components()).expect(\"Could not create fetch_state, Please initialize all referenced components before transmuting.\");\n        let filter_state = NewF::get_state(world.components()).expect(\"Could not create filter_state, Please initialize all referenced components before transmuting.\");\n\n        let mut self_access = self.component_access.clone();\n        if D::IS_READ_ONLY {\n            // The current state was transmuted from a mutable\n            // `QueryData` to a read-only one.\n            // Ignore any write access in the current state.\n            self_access.access_mut().clear_writes();\n        }\n\n        NewD::update_component_access(&fetch_state, &mut component_access);\n        NewD::provide_extra_access(\n            &mut fetch_state,\n            component_access.access_mut(),\n            self_access.access(),\n        );\n\n        let mut filter_component_access = FilteredAccess::default();\n        NewF::update_component_access(&filter_state, &mut filter_component_access);","sourceCodeStart":684,"sourceCodeEnd":720,"githubUrl":"https://github.com/bevyengine/bevy/blob/396ca727080776bd313bb892423b7d94e03b81b4/crates/bevy_ecs/src/query/state.rs#L684-L720","documentation":"Panic from QueryState::transmute_filtered: constructing the filter state (NewF) failed because a component used by the new filter is not initialized in the world, so its ComponentId/state could not be produced. Companion guard to the fetch-state check in the same method.","triggerScenarios":"Thrown at crates/bevy_ecs/src/query/state.rs:702 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Register the filter's components with the world before transmuting (init_component or an initial spawn)","Use a filter whose components are already part of the original query","Build QueryState::new directly for the filtered query instead of transmuting"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"396ca727080776bd313bb892423b7d94e03b81b4","analyzedAt":"2026-08-20T16:12:39.808Z","contentChangedAt":"2026-08-20T16:12:39.808Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}