- Home /
Keep Joint's variables after turning the gameObject off and on
I have 2 boxes (one above the other one at a few meters), both being rigid bodies. On one of them I have a Fixed Joint connected to the other box.
I have this script on both boxes (this is just to easily reproduce the issue, the actual setup in one of my projects is more complicated and I really have to turn off and on the game objects):
void FixedUpdate ()
{
gameObject.SetActive(false);
gameObject.SetActive(true);
}
The issue that I encounter is that after the box from the bottom is hitting the ground, the one from above is starting to slowly fall.
I was thinking about saving the joint's variables before turning off the game object and restoring them after turning on the game object, but the joint obviously has hidden variables that are not accessible.
What can I do so the joint still works properly after adding that script to both objects?
I've solved my issue by setting is$$anonymous$$inematic and detectCollisions on my rigidbodies, ins$$anonymous$$d of turning the gameObjects on and off.