- Home /
Disabling/Enabling GameObjects with Attached Rigidbody Components leads to strange behavior
Hi,
I am porting an existing, large Unity game to a mobile platform. Because there are performance issues, I am interested in disabling all but the room the player is currently in for each level. The approach basically works, but there are some issues.
Game objects with attached RigidBody components start behaving very strangely when they are enabled after first being disabled. They start moving around erratically, and don't seem to handle collisions anymore. I have been able to work around some of these issues by explicitly setting the freezeRotation and isKinematic properties for RigidBody components, but the overall behavior is still off.
I am new to Unity and apologize if this is a noobish questions, or if the solution seems obvious.
A little bit more background regarding the issue: all objects are ultimately parented to the room that they are in. When the player transfers from one room to the next, I turn off objects in the current room by calling oldRoom.SetActiveRecursively(false), and activate the new room by calling newRoom.SetActiveRecursively(true).
Disclaimer for posters that wish to point me towards occlusion culling: I know about occlusion culling as a standard way to increase performance, but it doesn't seem appropriate in my case, as I am running low on memory, and don't have room for occlusion maps.
Have you set the rigidbody.velocity and .angularVelocity to Vector3.zero? I've found that disabling and enabling doesn't always clear any internal variables, so when a GO is enabled, it might carry old velocities to new places. Try enabling, then setting the two velocities to zero in your script.
I have a similar problem. A ragdoll character in my game is SetActiveRecursively(false) at the beginning, then later on, I change its position and SetActiveRecursively(true). The various sub-components of the character seem to be split up into different places in the scene. The rigid bodies attached to the limbs appear in a pile along with the mesh somewhere above the ceiling, but the root gameobject of the character and some of the colliders appear at the correct location.
Answer by Lekta · Dec 10, 2010 at 09:19 AM
I have same troubles with rigidbodies. When I reenable them, GO starts move uncontrollably. Know anybody solution?
Your answer
![](https://koobas.hobune.stream/wayback/20220613080511im_/https://answers.unity.com/themes/thub/images/avi.jpg)