{"record":{"id":"e1c17300eb0139b4","repo":"stride3d/stride","slug":"the-mass-of-a-rigidbody-cannot-be-negative","errorCode":null,"errorMessage":"the Mass of a Rigidbody cannot be negative.","messagePattern":"the Mass of a Rigidbody cannot be negative\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Physics/Elements/RigidbodyComponent.cs","lineNumber":83,"sourceCode":"        /// <value>\n        /// true, false\n        /// </value>\n        /// <userdoc>\n        /// Objects with higher mass push objects with lower mass more when they collide. For large differences, use point values; for example, write 0.1 or 10, not 1 or 100000.\n        /// </userdoc>\n        [DataMember(80)]\n        [DataMemberRange(0, 6)]\n        public float Mass\n        {\n            get\n            {\n                return mass;\n            }\n            set\n            {\n                if (value < 0)\n                {\n                    throw new InvalidOperationException(\"the Mass of a Rigidbody cannot be negative.\");\n                }\n\n                mass = value;\n\n                if (InternalRigidBody == null)\n                {\n                    return;\n                }\n                    \n\n                var inertia = ColliderShape.InternalShape.CalculateLocalInertia(value);\n                InternalRigidBody.SetMassProps(value, inertia);\n                InternalRigidBody.UpdateInertiaTensor(); //this was the major headache when I had to debug Slider and Hinge constraint\n            }\n        }\n\n        /// <summary>\n        /// Gets the collider shape.","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Physics/Elements/RigidbodyComponent.cs#L65-L101","documentation":"Thrown by the RigidbodyComponent.Mass setter when a negative value is assigned. Mass is a physical property that must be non-negative (zero being used for special cases); a negative mass has no physical meaning and would corrupt the physics simulation, so the setter rejects it with an InvalidOperationException. The property is documented with DataMemberRange(0, 6) and user docs advising realistic point values.","triggerScenarios":"Setting rigidbody.Mass to any value < 0; computing mass from data that can go negative (e.g. difference calculations); deserializing configs with negative values.","commonSituations":"UI sliders or config files allowing negatives; script math producing negative mass; mass = -1 used as a sentinel for 'dynamic/auto' in other engines carried over incorrectly.","solutions":["Only assign Mass >= 0 (0 typically means static/kinematic handling per engine conventions)","Clamp the value: rigidbody.Mass = Math.Max(0f, computedMass)","Check any config/UI producing mass values for negative ranges"],"exampleFix":"// before\nrigidbody.Mass = -1f; // throws\n// after\nrigidbody.Mass = Math.Max(0f, computedMass);","handlingStrategy":"validation","validationCode":"if (mass < 0f) throw new ArgumentOutOfRangeException(nameof(mass), \"Mass cannot be negative.\");\nrigidbody.Mass = mass;","typeGuard":null,"tryCatchPattern":"try { rigidbody.Mass = value; }\ncatch (InvalidOperationException) { /* clamp and retry */ rigidbody.Mass = 0f; }","preventionTips":["Clamp computed mass values with Math.Max(0f, m)","Restrict UI/config ranges to >= 0","Never use negative mass as a sentinel value"],"tags":["physics","rigidbody","csharp"],"backgroundTag":"invalid-argument-value","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}