{"record":{"id":"f94fe403ebe64c1f","repo":"bevyengine/bevy","slug":"component-already-has-an-on-remove-hook","errorCode":null,"errorMessage":"Component already has an on_remove hook","messagePattern":"Component already has an on_remove hook","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/bevy_ecs/src/lifecycle.rs","lineNumber":240,"sourceCode":"    /// As a result, this needs to be combined with immutable components to serve as a mechanism for reliably updating indexes and other caches.\n    ///\n    /// # Panics\n    ///\n    /// Will panic if the component already has an `on_discard` hook\n    pub fn on_discard(&mut self, hook: ComponentHook) -> &mut Self {\n        self.try_on_discard(hook)\n            .expect(\"Component already has an on_discard hook\")\n    }\n\n    /// Register a [`ComponentHook`] that will be run when this component is removed from an entity.\n    /// Despawning an entity counts as removing all of its components.\n    ///\n    /// # Panics\n    ///\n    /// Will panic if the component already has an `on_remove` hook\n    pub fn on_remove(&mut self, hook: ComponentHook) -> &mut Self {\n        self.try_on_remove(hook)\n            .expect(\"Component already has an on_remove hook\")\n    }\n\n    /// Register a [`ComponentHook`] that will be run for each component on an entity when it is despawned.\n    ///\n    /// # Panics\n    ///\n    /// Will panic if the component already has an `on_despawn` hook\n    pub fn on_despawn(&mut self, hook: ComponentHook) -> &mut Self {\n        self.try_on_despawn(hook)\n            .expect(\"Component already has an on_despawn hook\")\n    }\n\n    /// Attempt to register a [`ComponentHook`] that will be run when this component is added to an entity.\n    ///\n    /// This is a fallible version of [`Self::on_add`].\n    ///\n    /// Returns `None` if the component already has an `on_add` hook.\n    pub fn try_on_add(&mut self, hook: ComponentHook) -> Option<&mut Self> {","sourceCodeStart":222,"sourceCodeEnd":258,"githubUrl":"https://github.com/bevyengine/bevy/blob/396ca727080776bd313bb892423b7d94e03b81b4/crates/bevy_ecs/src/lifecycle.rs#L222-L258","documentation":"Panic in ComponentLifecycleHook registration (on_remove): the component already has an on_remove hook stored, so try_on_remove could not install the new one and the expect fired. Same single-slot Option storage guard as the other lifecycle events.","triggerScenarios":"Thrown at crates/bevy_ecs/src/lifecycle.rs:240 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Register on_remove once; combine multiple concerns in one hook closure","Trace which plugin or configure_hooks call registered the first hook and de-duplicate","Use try_on_remove for cooperative registration"],"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-14T05:17:10.506Z"}