{"record":{"id":"596bf24f0b65d247","repo":"stride3d/stride","slug":"trying-to-remove-unregistered-collider","errorCode":null,"errorMessage":"Trying to remove unregistered collider","messagePattern":"Trying to remove unregistered collider","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Navigation/NavigationMeshBuilder.cs","lineNumber":72,"sourceCode":"            lock (colliders)\n            {\n                if (registeredGuids.Contains(colliderData.Component.Id))\n                    throw new InvalidOperationException(\"Duplicate collider added\");\n                colliders.Add(colliderData);\n                registeredGuids.Add(colliderData.Component.Id);\n            }\n        }\n\n        /// <summary>\n        /// Removes a specific collider from the builder\n        /// </summary>\n        /// <param name=\"colliderData\">The collider data object to remove</param>\n        public void Remove(StaticColliderData colliderData)\n        {\n            lock (colliders)\n            {\n                if (!registeredGuids.Contains(colliderData.Component.Id))\n                    throw new InvalidOperationException(\"Trying to remove unregistered collider\");\n                colliders.Remove(colliderData);\n                registeredGuids.Remove(colliderData.Component.Id);\n            }\n        }\n\n        /// <summary>\n        /// Performs the build of a navigation mesh\n        /// </summary>\n        /// <param name=\"buildSettings\">The build settings to pass to recast</param>\n        /// <param name=\"groups\">A collection of agent settings to use, this will generate a layer in the navigation mesh for every agent settings in this collection (in the same order)</param>\n        /// <param name=\"includedCollisionGroups\">The collision groups that will affect which colliders are considered solid</param>\n        /// <param name=\"boundingBoxes\">A collection of bounding boxes to use as the region for which to generate navigation mesh tiles</param>\n        /// <param name=\"cancellationToken\">A cancellation token to interrupt the build process</param>\n        /// <returns>The build result</returns>\n        public NavigationMeshBuildResult Build(NavigationMeshBuildSettings buildSettings, ICollection<NavigationMeshGroup> groups, CollisionFilterGroupFlags includedCollisionGroups,\n            ICollection<BoundingBox> boundingBoxes, CancellationToken cancellationToken)\n        {\n            var lastCache = oldNavigationMesh?.Cache;","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Navigation/NavigationMeshBuilder.cs#L54-L90","documentation":"NavigationMeshBuilder.Remove unregisters a collider by its component Id. Throwing InvalidOperationException when the Id is not registered catches lifecycle bugs where removal happens for a collider that was never added or was already removed.","triggerScenarios":"Calling Remove(StaticColliderData) for a component that was never passed to Add, calling Remove twice for the same component, or removing after the builder state was reset.","commonSituations":"Asymmetric add/remove lifecycle in scene teardown; removing a collider from a different NavigationMeshBuilder instance than the one that added it; scripts running cleanup on scene unload twice.","solutions":["Check that the collider was registered with this builder before removing (track registration yourself or expose the registered set)","Make add/remove lifecycle symmetric: remove only in response to the matching removal of a previously added component","Swallow the case intentionally by checking membership first if double-removal is expected in your teardown flow"],"exampleFix":"// before\nbuilder.Remove(colliderData); // may be unregistered\n// after\nif (registered.Contains(colliderData.Component.Id))\n    builder.Remove(colliderData);","handlingStrategy":"validation","validationCode":"// only remove what you added\nif (addedColliders.Remove(colliderData))\n    builder.Remove(colliderData);","typeGuard":"null","tryCatchPattern":"try\n{\n    builder.Remove(colliderData);\n}\ncatch (InvalidOperationException)\n{\n    // not registered; ignore during teardown\n}","preventionTips":["Keep a local record of what was added to which builder","Make teardown idempotent and check membership before Remove","Remove on the same builder instance that performed Add"],"tags":["csharp","invalid-state","navigation"],"backgroundTag":"invalid-state-transition","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}