CodexBloom - Programming Q&A Platform

Unity 2021: implementing Rigidbody configuration guide to forces after disabling and re-enabling

👀 Views: 69 đŸ’Ŧ Answers: 1 📅 Created: 2025-07-07
unity3d rigidbody physics C#

I'm relatively new to this, so bear with me. I'm working with a frustrating scenario with a Rigidbody in Unity 2021.3.7f1. I have a player object that I temporarily disable the Rigidbody component on when entering a specific UI menu, and then I re-enable it when exiting the menu. My intention is to stop all physics interactions while the menu is open. However, after re-enabling the Rigidbody, it doesn't respond to forces or gravity anymore. Instead, it just sits at its last position without moving. Here's what my code looks like for toggling the menu: ```csharp public class MenuController : MonoBehaviour { public GameObject menuPanel; public Rigidbody playerRigidbody; public void ToggleMenu() { bool isActive = menuPanel.activeSelf; menuPanel.SetActive(!isActive); if (isActive) { playerRigidbody.isKinematic = false; // Re-enable physics } else { playerRigidbody.isKinematic = true; // Disable physics } } } ``` I confirmed that the Rigidbody becomes kinematic when the menu is activated, but after setting it back to non-kinematic, I also tried resetting the velocity: ```csharp playerRigidbody.velocity = Vector3.zero; playerRigidbody.angularVelocity = Vector3.zero; ``` Despite this, the Rigidbody still doesn't respond to forces like `AddForce` afterwards. I checked for any constraints in the Rigidbody settings and found none. I even tried adding a small force right after re-enabling it: ```csharp if (!isActive) { playerRigidbody.AddForce(Vector3.up * 5f, ForceMode.Impulse); } ``` Still nothing happens. I also verified that there are no other scripts affecting the Rigidbody state. The player object is not being destroyed or instantiated again; I'm simply enabling/disabling the Rigidbody. Has anyone faced a similar scenario or have an idea of what might be going wrong? I would greatly appreciate any insights into this behavior. I recently upgraded to C# 3.11. Any advice would be much appreciated.