{"record":{"id":"7329da8a0e0ccecf","repo":"stride3d/stride","slug":"attempt-was-made-to-create-a-physics-constraint-but-one-of","errorCode":null,"errorMessage":"Attempt was made to create a physics constraint, but one of the rigidbodies has not been initialized by the PhysicsProcessor.","messagePattern":"Attempt was made to create a physics constraint, but one of the rigidbodies has not been initialized by the PhysicsProcessor\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Physics/Engine/PhysicsConstraintProcessor.cs","lineNumber":112,"sourceCode":"                DisposeOf(component);\n            }\n            \n            if (component.Enabled)\n            {\n                if (component.Description == null || component.BodyA == null)\n                {\n                    logger.Warning(\"ConstraintComponent with an empty description or missing required body. Skipping constraint creation.\");\n                    return;\n                }\n\n                // this can happen when the constraint component is added to the processor\n                // before the rigidbodies are added\n                if (component.BodyA?.InternalRigidBody == null || component.BodyB != null && component.BodyB.InternalRigidBody == null)\n                {\n                    if (skipUninitializedComponents)\n                        return;\n                    else\n                        throw new InvalidOperationException(\"Attempt was made to create a physics constraint, but one of the rigidbodies has not been initialized by the PhysicsProcessor.\");\n                }\n\n                component.Constraint = component.Description.Build(\n                    component.BodyA,\n                    component.BodyB);\n                component.Simulation = component.BodyA.Simulation;\n                component.Simulation.AddConstraint(component.Constraint, component.DisableCollisionsBetweenBodies);\n                component.Detached = false;\n            }\n        }\n\n        private void DisposeOf(PhysicsConstraintComponent component)\n        {\n            // A disposed constraint will have internal == null\n            if (component.Constraint != null && component.Constraint.InternalConstraint != null)\n            {\n                component.Constraint.Dispose();\n            }","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Physics/Engine/PhysicsConstraintProcessor.cs#L94-L130","documentation":"PhysicsConstraintProcessor.Recreate builds the native physics constraint from its description, which requires both referenced rigidbodies to have native counterparts (InternalRigidBody != null). If a rigidbody referenced by BodyA/BodyB has not yet been initialized by the PhysicsProcessor, and skipping uninitialized components is disabled, this InvalidOperationException is thrown.","triggerScenarios":"Adding or updating a PhysicsConstraintComponent whose BodyA (or non-null BodyB) is a RigidbodyComponent that has not yet been processed/initialized by the PhysicsProcessor, when Recreate runs from OnEntityComponentAdding or Update with skipUninitializedComponents == false.","commonSituations":"Adding a constraint and its rigidbodies to an entity at the same time (order not guaranteed); referencing a rigidbody on another entity that is not yet in the scene; loading scenes where constraints are processed before bodies.","solutions":["Ensure both referenced rigidbodies are added to entities in a physics-processed scene before the constraint component.","Order component addition so rigidbodies are added/processed before the constraint.","Enable/keep skipUninitializedComponents so constraints with uninitialized bodies are retried on later updates instead of throwing.","Verify BodyA/BodyB assignments point to rigidbodies that actually exist and are enabled."],"exampleFix":"// before\nentity.Add(constraintComponent); // may throw if bodies not yet initialized\n// after\nif (constraintComponent.BodyA?.InternalRigidBody != null &&\n    (constraintComponent.BodyB == null || constraintComponent.BodyB.InternalRigidBody != null))\n{\n    entity.Add(constraintComponent);\n}","handlingStrategy":"validation","validationCode":"bool ready = constraint.BodyA?.InternalRigidBody != null &&\n             (constraint.BodyB == null || constraint.BodyB.InternalRigidBody != null);\nif (!ready) return; // defer constraint creation until bodies are initialized","typeGuard":null,"tryCatchPattern":"try { entity.Add(constraintComponent); }\ncatch (InvalidOperationException ex) { /* bodies not yet initialized; retry after physics update */ }","preventionTips":["Add rigidbodies to the scene before constraint components","Keep skipUninitializedComponents enabled so constraints are deferred instead of throwing","Verify BodyA/BodyB references point to existing enabled rigidbodies"],"tags":["physics","constraints","initialization-order"],"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-23T08:17:48.524Z"}