Rigidbody sleeping prevents collision detection

Hello, I’m trying to detect the collision between two game objects. The first object is a static sphere collider with a rigidbody attached, on a user defined layer and no gravity enabled.

The second object is a user controlled sphere collider (parented) with no rigidbody attached and on the same user defined layer as the static collider.

I think because the first static game object doesn’t move, its rigidbody goes to sleep and stops detecting collision with the player.

And so I’ve added a rigidbody to the player on the parented sphere collider. But I think because the rigidbody is parented to the player and I use a character controller to move the player, that rigidbody is also considered nonmoving and also goes to sleep.

How am I supposed to detect collisions now? Is there a certain best practice to follow when creating my player prefabs in terms of components and parenting?

You may have already read through this page, but it explains all the combinations that work: Unity - Manual: Introduction to rigid body physics (Was: http://docs.unity3d.com/Documentation/Components/RigidbodySleeping.html)

If your first object is static and you just want to know when player (second object) enters its bounds, you could remove the first object’s rigidbody and make it a static trigger.

I don’t think the player’s rigidbody child should fall asleep.

Are your layers correct? Double-check Edit > Project Settings > Physics to make sure collisions are enabled.

To get verification that sleeping is the real problem, you could add a temporary test script to keep the rigidbodies awake. Something like:

void Update() {
    if ((rigidbody != null) && rigidbody.IsSleeping()) {
        rigidbody.WakeUp();
    }
}

If they still fail to register collisions, then it’s not a sleep problem.

I know this is an old thread, but I had a similar problem, and to fix it I did the following:
On the rigidbody I set

  • collision detection to continuous
  • sleeping mode to never sleep

and it seemed to work for me.

You can set Rigidbody.sleepThreshold to 0 to disable rigidbody sleeping feature.

    m_Rigidbody = GetComponent<Rigidbody>();
    m_Rigidbody.sleepThreshold = 0.0f;

You can use

void Start()
{
this.GetComponent<Rigidbody>().sleepThreshold = 0.0f;
}

this worked for me