stride3d/stride · error · Exception
must be valid
Error message
{nameof(rigidBodyA)} must be valid What it means
CreateConstraintInternal is the shared private path for all constraint factories. It requires a non-null rigidBodyA (the primary body) and throws with the message "rigidBodyA must be valid" (interpolated via nameof). This is an internal invariant enforced on the common path used by CreateConstraint and both hinge overloads.
Solutions
- Resolve and validate rigidBodyA before calling any CreateConstraint/CreateHingeConstraint API.
- Check entity assignment in the editor / component lookups so the primary body is present.
- Wrap constraint setup in a guard that logs which body reference is missing.
Example fix
// before
Simulation.CreateConstraint(ConstraintTypes.Hinge, rigidBodyA, rigidBodyB, frameA, frameB); // rigidBodyA null
// after
var rbA = Entity.GetComponent<RigidbodyComponent>() ?? throw new InvalidOperationException("rigidBodyA must be valid");
Simulation.CreateConstraint(ConstraintTypes.Hinge, rbA, rigidBodyB, frameA, frameB); Defensive patterns
Strategy: type-guard
Validate before calling
if (rigidBodyA == null) throw new InvalidOperationException("rigidBodyA must be valid"); Type guard
RigidbodyComponent RequireBody(RigidbodyComponent b) => b ?? throw new InvalidOperationException("rigidBodyA must be valid"); Try / catch
try { CreateConstraints(...); } catch (Exception ex) when (ex.Message.Contains("rigidBodyA must be valid")) { /* re-resolve primary body */ } Prevention
- Make the primary body an explicit, validated constructor/script parameter.
- Fail at component init when the primary body is missing.
- Don't forward possibly-null bodies into generic constraint helpers.
When it happens
Trigger: Any constraint factory invoked with rigidBodyA == null — e.g. Simulation.CreateConstraint(type, null, bodyB, ...) or CreateHingeConstraint(null, ...) reaching the internal path.
Common situations: Generic helper code that passes whichever body variable happens to be first; editor field left unassigned; Get<T> lookups returning null on wrong entities.
Related errors
- Both RigidBodies must be valid
- RigidBody 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/f4dac6ba1d08708e.
Report an issue: GitHub.
Appendix: source
Thrown at sources/engine/Stride.Physics/Simulation.cs:695
/// <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>
public static HingeConstraint CreateHingeConstraint(RigidbodyComponent rigidBodyA, Vector3 pivotInA, Vector3 axisInA, RigidbodyComponent rigidBodyB, Vector3 pivotInB, Vector3 axisInB, bool useReferenceFrameA = false)
{
if (rigidBodyA == null || rigidBodyB == null) throw new Exception("Both RigidBodies must be valid");
return CreateHingeConstraintInternal(rigidBodyA, rigidBodyB, pivotInA, pivotInB, axisInA, axisInB, useReferenceFrameA);
}
static Constraint CreateConstraintInternal(ConstraintTypes type, RigidbodyComponent rigidBodyA, Matrix frameA, RigidbodyComponent rigidBodyB = null, Matrix frameB = default, bool useReferenceFrameA = false)
{
if (rigidBodyA == null) throw new Exception($"{nameof(rigidBodyA)} must be valid");
if (rigidBodyB != null && rigidBodyB.Simulation != rigidBodyA.Simulation) throw new Exception("Both RigidBodies must be on the same simulation");
Constraint constraintBase;
var rbA = rigidBodyA.InternalRigidBody;
var rbB = rigidBodyB?.InternalRigidBody;
switch (type)
{
case ConstraintTypes.Point2Point:
{
var constraint = new Point2PointConstraint
{
InternalPoint2PointConstraint =
rigidBodyB == null ?
new BulletSharp.Point2PointConstraint(rbA, frameA.TranslationVector ) :
new BulletSharp.Point2PointConstraint(rbA, rbB, frameA.TranslationVector, frameB.TranslationVector),
};
constraintBase = constraint;
View on GitHub (pinned to 96fad776d2)