stride3d/stride · error · InvalidOperationException

PhysicsComponent has not been attached yet.

Error message

PhysicsComponent has not been attached yet.

What it means

PhysicsComponent.ReAttach() re-integrates components when their properties may not be fully set up (e.g. after GetOrCreate<RigidbodyComponent> or adding collider shapes). It throws InvalidOperationException when Data is null, meaning the component was never attached to its physics engine counterpart via Attach, so there is nothing to re-integrate.

Solutions

  1. Ensure the PhysicsComponent is added to an entity in a scene being processed by the PhysicsProcessor before calling ReAttach.
  2. Guard the call with a null check on Data (or the internal attachment state) before invoking ReAttach.
  3. Defer shape/component mutations until after the first physics update (e.g. Script start/Update) rather than during construction.
  4. If the component is genuinely unattached, call Attach (or the appropriate setup path) instead of ReAttach.

Example fix

// before
physicsComponent.ReAttach(); // throws if never attached
// after
if (physicsComponent.Data != null)
    physicsComponent.ReAttach();
Defensive patterns

Strategy: validation

Validate before calling

if (physicsComponent.Data != null)
    physicsComponent.ReAttach();

Try / catch

try { physicsComponent.ReAttach(); }
catch (InvalidOperationException ex) { /* component not yet attached; defer until after physics processing */ }

Prevention

When it happens

Trigger: Calling ReAttach() (directly or via property-change callbacks that trigger reintegration) on a PhysicsComponent before it has been attached — i.e. before Data has been assigned by the physics processing/attach step.

Common situations: Modifying collider shapes or rigidbody properties in code that runs before the entity has been processed by the PhysicsProcessor (e.g. in a constructor or before the component is added to an entity/scene); calling ReAttach manually during scene load ordering issues.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


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

Appendix: source

Thrown at sources/engine/Stride.Physics/Engine/PhysicsComponent.cs:703

            {
                foreach(var kvp in ignoreCollisionBuffer)
                {
                    IgnoreCollisionWith(kvp.Key, kvp.Value);
                }
                ignoreCollisionBuffer = null;
            }

            attachInProgress = false;
        }

        /// <summary>
        /// Ran when properties of Components may not be fully setup and need to be reintegrated (eg GetOrCreate<RigidbodyComponent> and adding collidershapes)
        /// </summary>
        internal void ReAttach()
        {
            if (Data == null)
            {
                throw new InvalidOperationException("PhysicsComponent has not been attached yet.");
            }
            //TODO: Could consider fully detaching and then rebuilding, but ideally this would cause null refs on Rigidbody OnDetach calls
            //Shouldnt call detach, because at this point the user has added new components and this runs as a check to rebuild as needed.
            //Entire wipes to rebuild causes loss in the data that the user has just added (and is slower)

            Entity.Transform.UpdateWorldMatrix();

            BoneIndex = -1;

            OnAttach();

            //ensure ignore collisions
            if (ignoreCollisionBuffer != null && NativeCollisionObject != null)
            {
                foreach (var kvp in ignoreCollisionBuffer)
                {
                    IgnoreCollisionWith(kvp.Key, kvp.Value);
                }

View on GitHub (pinned to 96fad776d2)