{"record":{"id":"4d58f10cf93aa9e5","repo":"stride3d/stride","slug":"rigidbody-must-be-valid","errorCode":null,"errorMessage":"RigidBody must be valid","messagePattern":"RigidBody must be valid","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Physics/Simulation.cs","lineNumber":667,"sourceCode":"            if (rigidBodyA == null || rigidBodyB == null) throw new Exception(\"Both RigidBodies must be valid\");\n            return CreateConstraintInternal(type, rigidBodyA, frameA, rigidBodyB, frameB, useReferenceFrameA);\n        }\n\n        /// <summary>\n        /// Creates a hinge constraint using a specialized constructor.\n        /// </summary>\n        /// <param name=\"rigidBodyA\">The rigid body a.</param>\n        /// <param name=\"pivotInA\">Pivot point in body a.</param>\n        /// <param name=\"axisInA\">Axis in body a.</param>\n        /// <param name=\"useReferenceFrameA\">if set to <c>true</c> [use reference frame a].</param>\n        /// <exception cref=\"System.Exception\">\n        /// Cannot perform this action when the physics engine is set to CollisionsOnly\n        /// or\n        /// RigidBody must be valid\n        /// </exception>\n        public static HingeConstraint CreateHingeConstraint(RigidbodyComponent rigidBodyA, Vector3 pivotInA, Vector3 axisInA, bool useReferenceFrameA = false)\n        {\n            if (rigidBodyA == null) throw new Exception(\"RigidBody must be valid\");\n            return CreateHingeConstraintInternal(rigidBodyA, null, pivotInA, default, axisInA, default, useReferenceFrameA);\n        }\n\n        /// <summary>\n        /// Creates a hinge constraint using a specialized constructor.\n        /// </summary>\n        /// <param name=\"rigidBodyA\">The rigid body a.</param>\n        /// <param name=\"pivotInA\">Pivot point in body a.</param>\n        /// <param name=\"axisInA\">Axis in body a.</param>\n        /// <param name=\"rigidBodyB\">The rigid body b.</param>\n        /// <param name=\"pivotInB\">Pivot point in body b.</param>\n        /// <param name=\"axisInB\">Axis in body b.</param>\n        /// <param name=\"useReferenceFrameA\">if set to <c>true</c> [use reference frame a].</param>\n        /// <exception cref=\"System.Exception\">\n        /// Cannot perform this action when the physics engine is set to CollisionsOnly\n        /// or\n        /// Both RigidBodies must be valid\n        /// </exception>","sourceCodeStart":649,"sourceCodeEnd":685,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Physics/Simulation.cs#L649-L685","documentation":"The single-body CreateHingeConstraint overload builds a hinge between one rigid body and the world. rigidBodyA anchors the hinge and is required; passing null would dereference into the native Bullet constructor, so the API throws a validation exception first.","triggerScenarios":"Calling Simulation.CreateHingeConstraint(null, pivotInA, axisInA) — usually because a component lookup or field assignment returned null.","commonSituations":"Hinge setup in a script whose rigid body reference was never assigned in the editor or found via entity.Get<RigidbodyComponent>() returning null.","solutions":["Assign/resolve the RigidbodyComponent before creating the hinge constraint.","Validate the reference with a null check and fail early with a clear message.","Move hinge creation to Start/scene-loaded time when components are guaranteed initialized."],"exampleFix":"// before\nvar hinge = Simulation.CreateHingeConstraint(rigidBodyA, pivot, axis); // rigidBodyA null\n// after\nvar hinge = Simulation.CreateHingeConstraint(rigidBodyA ?? Entity.Get<RigidbodyComponent>(), pivot, axis);","handlingStrategy":"type-guard","validationCode":"if (rigidBodyA == null) throw new InvalidOperationException(\"rigidBodyA must be assigned before creating hinge\");","typeGuard":"bool IsValidBody(RigidbodyComponent b) => b != null && b.Simulation != null;","tryCatchPattern":"try { var h = Simulation.CreateHingeConstraint(a, pivot, axis); } catch (Exception ex) when (ex.Message == \"RigidBody must be valid\") { /* fix body reference */ }","preventionTips":["Assign hinge body references in the editor and validate on Start.","Prefer Entity.Get<RigidbodyComponent>() with null check over raw fields.","Create constraints only after scene initialization."],"tags":["physics","stride","null-reference","constraint"],"backgroundTag":"null-argument","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"}