Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Josh707 · Apr 07, 2014 at 08:40 PM · rigidbodyontriggerstaysleep

Preventing rigidbody sleeping altogether

As the title says, is there any way to completely prevent a rigidbody from sleeping, without having to add 0 force or set their position to their position? Setting the sleep velocity/angular velocity to 0 doesn't prevent it, once they actually stop moving they go to sleep.

In my scenario I am dropping salt piles to slow & kill slugs that collide with individual salt particles. I use OnTriggerStay to determine if they are touching one and it works, but as soon as the salt particles come to a rest and sleep they stop detecting collisions.

I've looked up a few other similar questions and they all seem to have solved it by doing stuff like this:

 transform.position = transform.position;
 transform.Translate(0,0,0);
 rigidbody.AddForce(Vector3.zero);

There will potentially be hundreds of salt particles on the screen at a time, I don't want to have to throw them into a list and loop through it every frame just to set their position to where it already is or add no force, then remove them when they're dissolved. The slugs aren't using rigidbodies, I didn't want them able to push the salt around though I may just end up doing that if there's no way to prevent sleeping without executing some code every frame.

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image robertbu · Apr 11, 2014 at 07:40 AM 0
Share

If you go to:

Edit > Project Settings > Physics

...and set Sleep Velocity to 0.0 or you set the velocity directly:

 rigidbody.sleepVelocity = 0.0;

Does this solve the problem?

avatar image Josh707 · Apr 12, 2014 at 06:28 PM 0
Share

No, once they stop completely they seem to be put to sleep again and OnTriggerStay stops being called. I ended up parenting them all to an object and using GetComponentsInChildren to call WakeUp() on all the rigidbodies, it's not much of a problem but it'd be nice to be able to disable it.

4 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by plasticYoda · Jun 07, 2015 at 03:27 AM

I ended up with this:

 void Update () {
     if (rigidbody.IsSleeping())
         rigidbody.WakeUp();

 }

My player object doesnt move - the scenery moves towards it, so it would fall asleep pretty quickly and didnt collide with anything. I only had a rigidbody on the player, not the objects, and a sleeping player was the problem!

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
2

Answer by NathanJSmith · Aug 20, 2019 at 09:38 AM

You can set Rigidbody.sleepThreshold to 0 to prevent rigidbody sleeping.

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


Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Fergicide · Apr 09, 2020 at 12:25 PM

I believe "rigidbody.WakeUp();" is the best solution, but I think it should go in FixedUpdate, with perhaps [DefaultExecutionOrder(-100)] to have it run before other FixedUpdate instances for that rb.

Better to solve the issue on an individual basis than reduce Rigidbody.sleepThreshold globally and incur all of that physics performance hit.

My timer testing suggests WakeUp is much faster than "thisTransform.position = thisTransform.position" (cached transform).

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

24 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

need help in rigid body sleep 3 Answers

Can you have an OnTriggerX event with Sleeping rigidbodies? 1 Answer

What does rigidbodies sleeping have to do with collision detection? 0 Answers

Rigidbody not sleeping 1 Answer

Get Rigidbodies to Sleep Faster 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges