How to wakeup all rigidbodies when I change the gravity?

I know when I change the Physics.gravity,the sleeping rigidbodies will not automately wake up.So how to wake up all the rigdbodies in the scene?

I have a game where the player can spin the world and the way i activate and deactivate the rigid bodies is like this…

public GameObject[] levelRigidBodies;

void Awake()
{
     levelRigidBodies = GameObject.FindGameObjectsWithTag("Crate");
}


void disableRigids()
    {
        foreach (GameObject lvlRigid in LevelRigidBodies)
        {
            //disable all rigid bodies in the level.... otherwise the spin will send them flying
            lvlRigid.gameObject.active = false;
        }
    }

    void enableRigids()
    {
        foreach (GameObject lvlRigid in LevelRigidBodies)
        {
            /// reactivate the rigids so the interact with player as normal
            lvlRigid.gameObject.active = true;
        }
    }
}

As you can see all of my rigids have the same tag, but you could easily do things a bit differently. I may in the future just have a parent empty game object and have all of my level rigid bodies inside of that and use something like:

rigidContainer.GetComponentInChildren<Rigidbody>().active = false; // or true depending on where I use it

but seeing as I havent tested this method yet I can’t for sure say it works. Let me know if this can help.

Thanks,it helps a lot,I will put all the rigidbodys in the same parent GameObject.:slight_smile: