{"record":{"id":"3fd2792993169c39","repo":"stride3d/stride","slug":"physicscomponent-has-not-been-attached-yet","errorCode":null,"errorMessage":"PhysicsComponent has not been attached yet.","messagePattern":"PhysicsComponent has not been attached yet\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Physics/Engine/PhysicsComponent.cs","lineNumber":703,"sourceCode":"            {\n                foreach(var kvp in ignoreCollisionBuffer)\n                {\n                    IgnoreCollisionWith(kvp.Key, kvp.Value);\n                }\n                ignoreCollisionBuffer = null;\n            }\n\n            attachInProgress = false;\n        }\n\n        /// <summary>\n        /// Ran when properties of Components may not be fully setup and need to be reintegrated (eg GetOrCreate<RigidbodyComponent> and adding collidershapes)\n        /// </summary>\n        internal void ReAttach()\n        {\n            if (Data == null)\n            {\n                throw new InvalidOperationException(\"PhysicsComponent has not been attached yet.\");\n            }\n            //TODO: Could consider fully detaching and then rebuilding, but ideally this would cause null refs on Rigidbody OnDetach calls\n            //Shouldnt call detach, because at this point the user has added new components and this runs as a check to rebuild as needed.\n            //Entire wipes to rebuild causes loss in the data that the user has just added (and is slower)\n\n            Entity.Transform.UpdateWorldMatrix();\n\n            BoneIndex = -1;\n\n            OnAttach();\n\n            //ensure ignore collisions\n            if (ignoreCollisionBuffer != null && NativeCollisionObject != null)\n            {\n                foreach (var kvp in ignoreCollisionBuffer)\n                {\n                    IgnoreCollisionWith(kvp.Key, kvp.Value);\n                }","sourceCodeStart":685,"sourceCodeEnd":721,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Physics/Engine/PhysicsComponent.cs#L685-L721","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Ensure the PhysicsComponent is added to an entity in a scene being processed by the PhysicsProcessor before calling ReAttach.","Guard the call with a null check on Data (or the internal attachment state) before invoking ReAttach.","Defer shape/component mutations until after the first physics update (e.g. Script start/Update) rather than during construction.","If the component is genuinely unattached, call Attach (or the appropriate setup path) instead of ReAttach."],"exampleFix":"// before\nphysicsComponent.ReAttach(); // throws if never attached\n// after\nif (physicsComponent.Data != null)\n    physicsComponent.ReAttach();","handlingStrategy":"validation","validationCode":"if (physicsComponent.Data != null)\n    physicsComponent.ReAttach();","typeGuard":null,"tryCatchPattern":"try { physicsComponent.ReAttach(); }\ncatch (InvalidOperationException ex) { /* component not yet attached; defer until after physics processing */ }","preventionTips":["Only call ReAttach after the component is attached and processed by PhysicsProcessor","Do physics mutations in Script start/Update, not constructors","Check Data != null before reintegration calls"],"tags":["physics","invalid-state","lifecycle"],"backgroundTag":"invalid-state-transition","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"}