- Home /
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?
Answer by TonyLi · May 30, 2013 at 02:00 PM
You may have already read through this page, but it explains all the combinations that work: https://docs.unity3d.com/Manual/RigidbodiesOverview.html (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.
Thanks for the reply! I've checked that the layers and selected properly and their interactions were set alright.
Before reading your answer, I just added a 3rd rigidbody to the parent object and that fixed the problem.
I haven't followed through to verify if the rigidbody sleeping of the child collision mesh component was the problem.
To help others who might be reading this with a similar problem, what about the third rigidbody fixed your problem?
Answer by Obi02_ · Dec 11, 2018 at 07:01 AM
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.
Answer by NathanJSmith · Aug 20, 2019 at 09:41 AM
You can set Rigidbody.sleepThreshold to 0 to disable rigidbody sleeping feature.
m_Rigidbody = GetComponent<Rigidbody>();
m_Rigidbody.sleepThreshold = 0.0f;
Answer by amitDklein · Sep 14, 2020 at 05:22 PM
You can use
void Start()
{
this.GetComponent<Rigidbody>().sleepThreshold = 0.0f;
}
this worked for me
Your answer
![](https://koobas.hobune.stream/wayback/20220613103205im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Rigidbody not sleeping 1 Answer
rigid bodies passing through one another. 1 Answer
Rigidbody not colliding with walls 1 Answer
Rigidbody Precise Colliders 1 Answer
How to make an object 'push' my character out of the way upon collision? 0 Answers