{"record":{"id":"450081919c0a66c4","repo":"stride3d/stride","slug":"attempted-to-call-a-physics-function-that-is-avaliable-only","errorCode":null,"errorMessage":"Attempted to call a Physics function that is avaliable only when the Entity has been already added to the Scene.","messagePattern":"Attempted to call a Physics function that is avaliable only when the Entity has been already added to the Scene\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Physics/Elements/RigidbodyComponent.cs","lineNumber":444,"sourceCode":"        }\n\n        /// <summary>\n        /// Gets the total torque.\n        /// </summary>\n        /// <value>\n        /// The total torque.\n        /// </value>\n        public Vector3 TotalTorque => InternalRigidBody?.TotalTorque ?? Vector3.Zero;\n\n        /// <summary>\n        /// Applies the impulse.\n        /// </summary>\n        /// <param name=\"impulse\">The impulse.</param>\n        public void ApplyImpulse(Vector3 impulse)\n        {\n            if (InternalRigidBody == null)\n            {\n                throw new InvalidOperationException(\"Attempted to call a Physics function that is avaliable only when the Entity has been already added to the Scene.\");\n            }\n\n            InternalRigidBody.ApplyCentralImpulse(impulse);\n        }\n\n        /// <summary>\n        /// Applies the impulse.\n        /// </summary>\n        /// <param name=\"impulse\">The impulse.</param>\n        /// <param name=\"localOffset\">The local offset.</param>\n        public void ApplyImpulse(Vector3 impulse, Vector3 localOffset)\n        {\n            if (InternalRigidBody == null)\n            {\n                throw new InvalidOperationException(\"Attempted to call a Physics function that is avaliable only when the Entity has been already added to the Scene.\");\n            }\n\n            InternalRigidBody.ApplyImpulse(impulse, localOffset);","sourceCodeStart":426,"sourceCodeEnd":462,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Physics/Elements/RigidbodyComponent.cs#L426-L462","documentation":"ApplyImpulse(Vector3) forwards the impulse to the underlying Bullet rigid body, which only exists after the entity is added to the scene and physics processed it. If InternalRigidBody is null it throws InvalidOperationException explaining that physics functions require the entity to be in the scene.","triggerScenarios":"Calling ApplyImpulse before the entity was added to a scene, or in the same frame before physics processing created the internal body; calling it after the entity was removed.","commonSituations":"Calling ApplyImpulse in a constructor, Start() before scene attachment, or in a script's initialization before the physics processor ran; applying impulses to entities not part of the scene.","solutions":["Call ApplyImpulse only after the entity is added to the scene and physics is initialized (e.g. from Update or after PhysicsComponent processing)","Check rigidbody.InternalRigidBody != null before applying the impulse","Use a script Update/lifecycle method rather than construction/startup code"],"exampleFix":"// before\npublic MyScript() { rigidbody.ApplyImpulse(Vector3.UnitY * 10); } // InternalRigidBody null\n// after\npublic override void Update() { rigidbody.ApplyImpulse(Vector3.UnitY * 10); } // entity in scene, body ready","handlingStrategy":"validation","validationCode":"if (rigidbody.InternalRigidBody == null)\n    throw new InvalidOperationException(\"Entity must be added to the scene before ApplyImpulse.\");","typeGuard":null,"tryCatchPattern":"try { rigidbody.ApplyImpulse(impulse); }\ncatch (InvalidOperationException) { /* defer until entity is in scene */ }","preventionTips":["Apply impulses only after entity is added to the scene","Defer physics calls to Update/post-physics callbacks","Never call physics APIs from constructors"],"tags":["physics","rigidbody","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-23T08:17:48.524Z"}