stride3d/stride · error · NotSupportedException

NotSupportedException: value

Error message

NotSupportedException: value

What it means

The RigidBodyTypes property setter switches Bullet collision flags per type (Dynamic/Static/Kinematic). Any other value hits the default branch and throws NotSupportedException with the member name 'value'.

Solutions

  1. Only assign valid RigidBodyTypes values: Dynamic, Static, or Kinematic
  2. Validate the enum value with Enum.IsDefined before assigning
  3. Fix any int->enum casts producing out-of-range values

Example fix

// before
rigidbody.RigidBodyTypes = (RigidBodyTypes)42; // throws NotSupportedException
// after
var t = (RigidBodyTypes)42;
if (Enum.IsDefined(typeof(RigidBodyTypes), t))
    rigidbody.RigidBodyTypes = t;
Defensive patterns

Strategy: validation

Validate before calling

if (!Enum.IsDefined(typeof(RigidBodyTypes), value))
    throw new InvalidEnumArgumentException(nameof(value), (int)value, typeof(RigidBodyTypes));

Try / catch

try { rigidbody.RigidBodyTypes = t; }
catch (NotSupportedException) { /* invalid enum value from data */ }

Prevention

When it happens

Trigger: Assigning PhysicsComponent.RigidBodyTypes with an enum value outside the supported set, e.g. an invalid cast of an int to RigidBodyTypes.

Common situations: Loading enum values from config/serialization where the int no longer matches a defined enum member; adding a new enum member without updating this switch; cross-version data where the enum definition changed.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/0d730c892304734d. Report an issue: GitHub.

Appendix: source

Thrown at sources/engine/Stride.Physics/Elements/RigidbodyComponent.cs:295

                switch (value)
                {
                    case RigidBodyTypes.Dynamic:
                        InternalRigidBody.CollisionFlags &= ~(BulletSharp.CollisionFlags.StaticObject | BulletSharp.CollisionFlags.KinematicObject);
                        break;

                    case RigidBodyTypes.Static:
                        InternalRigidBody.CollisionFlags &= ~BulletSharp.CollisionFlags.KinematicObject;
                        InternalRigidBody.CollisionFlags |= BulletSharp.CollisionFlags.StaticObject;
                        break;

                    case RigidBodyTypes.Kinematic:
                        InternalRigidBody.CollisionFlags &= ~BulletSharp.CollisionFlags.StaticObject;
                        InternalRigidBody.CollisionFlags |= BulletSharp.CollisionFlags.KinematicObject;
                        break;

                    default:
                        throw new NotSupportedException(nameof(value));
                }
                if (!OverrideGravity)
                {
                    if (value == RigidBodyTypes.Dynamic)
                    {
                        InternalRigidBody.Gravity = Simulation.Gravity;
                    }
                    else
                    {
                        InternalRigidBody.Gravity = Vector3.Zero;
                    }
                }
                InternalRigidBody.InterpolationAngularVelocity = Vector3.Zero;
                InternalRigidBody.LinearVelocity = Vector3.Zero;
                InternalRigidBody.InterpolationAngularVelocity = Vector3.Zero;
                InternalRigidBody.AngularVelocity = Vector3.Zero;
            }
        }

View on GitHub (pinned to 96fad776d2)