CodexBloom - Programming Q&A Platform

Unity: Rigidbody not responding to gravity on dynamically spawned objects

👀 Views: 537 đŸ’Ŧ Answers: 1 📅 Created: 2025-07-17
unity rigidbody physics C#

I need some guidance on I'm working on a personal project and I'm learning this framework and I'm not sure how to approach I'm experiencing an issue where dynamically spawned GameObjects with a Rigidbody component are not responding to gravity as expected... I am using Unity 2023.1.0f1 and have set the Rigidbody's `useGravity` property to `true`, but the objects seem to hover in mid-air instead of falling. Here's the code I use to instantiate the objects: ```csharp public GameObject prefab; void Start() { SpawnObject(); } void SpawnObject() { GameObject obj = Instantiate(prefab, new Vector3(0, 10, 0), Quaternion.identity); Rigidbody rb = obj.GetComponent<Rigidbody>(); if (rb != null) { rb.useGravity = true; rb.isKinematic = false; // Ensure it's not kinematic } } ``` I have verified that the prefab has a Rigidbody component attached and that there are no scripts setting its position in an update loop or interfering with the physics simulation. Additionally, I've checked the Physics settings in Unity, and gravity is set to `-9.81` on the Y-axis. However, when the object spawns, it just stays at its initial position without falling. I also tried adding `rb.AddForce(Vector3.down * 10, ForceMode.Impulse);` right after instantiation, but that didn't seem to work either. The object does respond to other forces correctly if I apply them later, but gravity specifically appears to be ignored. Could there be any reason for this behavior? I've also tried using different colliders and ensuring there are no layers set to ignore gravity, but nothing seems to resolve the issue. Any help would be appreciated! I've been using C# for about a year now. Thanks for your help in advance! I'm on macOS using the latest version of C#. Cheers for any assistance! This is for a mobile app running on Windows 11. Any pointers in the right direction?