stride3d/stride · error · Exception
RigidBody must be valid
Error message
RigidBody must be valid
What it means
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.
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.
Example fix
// before var hinge = Simulation.CreateHingeConstraint(rigidBodyA, pivot, axis); // rigidBodyA null // after var hinge = Simulation.CreateHingeConstraint(rigidBodyA ?? Entity.Get<RigidbodyComponent>(), pivot, axis);
Defensive patterns
Strategy: type-guard
Validate before calling
if (rigidBodyA == null) throw new InvalidOperationException("rigidBodyA must be assigned before creating hinge"); Type guard
bool IsValidBody(RigidbodyComponent b) => b != null && b.Simulation != null;
Try / catch
try { var h = Simulation.CreateHingeConstraint(a, pivot, axis); } catch (Exception ex) when (ex.Message == "RigidBody must be valid") { /* fix body reference */ } Prevention
- 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.
When it happens
Trigger: Calling Simulation.CreateHingeConstraint(null, pivotInA, axisInA) — usually because a component lookup or field assignment returned null.
Common situations: Hinge setup in a script whose rigid body reference was never assigned in the editor or found via entity.Get<RigidbodyComponent>() returning null.
Related errors
- Both RigidBodies must be valid
- must be valid
- Both RigidBodies must be on the same simulation
- ArgumentNullException: descriptions
- ArgumentNullException: paramName
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/4d58f10cf93aa9e5.
Report an issue: GitHub.
Appendix: source
Thrown at sources/engine/Stride.Physics/Simulation.cs:667
if (rigidBodyA == null || rigidBodyB == null) throw new Exception("Both RigidBodies must be valid");
return CreateConstraintInternal(type, rigidBodyA, frameA, rigidBodyB, frameB, useReferenceFrameA);
}
/// <summary>
/// Creates a hinge constraint using a specialized constructor.
/// </summary>
/// <param name="rigidBodyA">The rigid body a.</param>
/// <param name="pivotInA">Pivot point in body a.</param>
/// <param name="axisInA">Axis in body a.</param>
/// <param name="useReferenceFrameA">if set to <c>true</c> [use reference frame a].</param>
/// <exception cref="System.Exception">
/// Cannot perform this action when the physics engine is set to CollisionsOnly
/// or
/// RigidBody must be valid
/// </exception>
public static HingeConstraint CreateHingeConstraint(RigidbodyComponent rigidBodyA, Vector3 pivotInA, Vector3 axisInA, bool useReferenceFrameA = false)
{
if (rigidBodyA == null) throw new Exception("RigidBody must be valid");
return CreateHingeConstraintInternal(rigidBodyA, null, pivotInA, default, axisInA, default, useReferenceFrameA);
}
/// <summary>
/// Creates a hinge constraint using a specialized constructor.
/// </summary>
/// <param name="rigidBodyA">The rigid body a.</param>
/// <param name="pivotInA">Pivot point in body a.</param>
/// <param name="axisInA">Axis in body a.</param>
/// <param name="rigidBodyB">The rigid body b.</param>
/// <param name="pivotInB">Pivot point in body b.</param>
/// <param name="axisInB">Axis in body b.</param>
/// <param name="useReferenceFrameA">if set to <c>true</c> [use reference frame a].</param>
/// <exception cref="System.Exception">
/// Cannot perform this action when the physics engine is set to CollisionsOnly
/// or
/// Both RigidBodies must be valid
/// </exception>View on GitHub (pinned to 96fad776d2)