{"record":{"id":"9df271b2a95d75cb","repo":"stride3d/stride","slug":"value-is-already-assigned-to-value-component-it-cannot-be","errorCode":null,"errorMessage":"{value} is already assigned to {value.Component}, it cannot be shared with {this}","messagePattern":"(.+?) is already assigned to (.+?), it cannot be shared with (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.BepuPhysics/Stride.BepuPhysics/CollidableComponent.cs","lineNumber":86,"sourceCode":"    /// <summary>\n    /// The collider definition used by this object.\n    /// </summary>\n    /// <remarks>\n    /// Changing this value will reset some of the internal physics state of this body\n    /// </remarks>\n    [NotNull]\n    [Display(category: CategoryCollider, Expand = ExpandRule.Always)]\n    public required ICollider Collider\n    {\n        get\n        {\n            return _collider;\n        }\n        set\n        {\n            if (value.Component != null && ReferenceEquals(value.Component, this) == false)\n            {\n                throw new InvalidOperationException($\"{value} is already assigned to {value.Component}, it cannot be shared with {this}\");\n            }\n\n            _collider.Component = null;\n            _collider = value;\n            _collider.Component = this;\n            TryUpdateFeatures();\n        }\n    }\n\n    /// <summary>\n    /// The bounce frequency in hz\n    /// </summary>\n    /// <remarks>\n    /// Must be low enough that the simulation can actually represent it.\n    /// If the contact is trying to make a bounce happen at 240hz,\n    /// but the integrator timestep is only 60hz,\n    /// the unrepresentable motion will get damped out and the body won't bounce as much.\n    /// <para>Defaults to <c>30</c>.</para>","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.BepuPhysics/Stride.BepuPhysics/CollidableComponent.cs#L68-L104","documentation":"A CollidableComponent's Collider property enforces one-to-one ownership: a collider shape instance already assigned to another component (value.Component != null and != this) cannot be shared. Assigning it here would silently move ownership and break the other component, so it throws InvalidOperationException before reassigning.","triggerScenarios":"Writing componentA.Collider = componentB.Collider, or reusing a cached ColliderShape instance across two CollidableComponents, while the previous owner still holds it.","commonSituations":"Cloning entities without cloning their collider assets, sharing prefab/cached colliders for performance, or copy-paste code assigning one entity's collider to another.","solutions":["Create a new collider instance for the second component instead of sharing (clone/duplicate the collider).","Detach from the previous owner first: set the other component's Collider to null, then assign here if you truly intend a move.","Fix the code path that reuses the collider reference (e.g. instantiate per-entity in clone logic)."],"exampleFix":"// before\nentityB.Get<CollidableComponent>().Collider = entityA.Get<CollidableComponent>().Collider; // shared!\n// after\nentityB.Get<CollidableComponent>().Collider = new SphereCollider(0.5f); // fresh instance","handlingStrategy":"validation","validationCode":"if (collider.Component != null && !ReferenceEquals(collider.Component, targetComponent)) {\n    throw new InvalidOperationException(\"Collider already owned by another component; clone it.\");\n}\ntargetComponent.Collider = collider;","typeGuard":null,"tryCatchPattern":"try { comp.Collider = sharedCollider; } catch (InvalidOperationException) { comp.Collider = CloneCollider(sharedCollider); }","preventionTips":["Instantiate a fresh collider per entity when cloning/prefab-instantiating","Never copy Collider properties between components directly","Null out the previous owner's Collider before intentionally moving a shared instance"],"tags":["physics","collider","ownership","state"],"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"}