• 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 Dmitry Pyalov · Feb 02, 2011 at 11:41 PM · physics

OnCollision events are not always fired

I have a root object with Rigidbody on it and few child colliders. I try to check if those coliders touch the terrain. So I use OnCollisionEnter/OnCollisionExit/OnCollisionStay to check if contact point with terrain is added or removed.

So I've faced the situation when those events are sometimes fired and sometimes not. For example if my object is lifted off ground it still may not receive OnCollisonExit calls for all contact points.

There is also a problem when the object is grounded it stops receiving OnCollisionStay calls in a few seconds.

It seems like a bug or some kind of special behaviour. I'm using the latest Unity v3.1

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Eric5h5 · Feb 03, 2011 at 12:05 AM

It's expected that OnCollisionStay messages will stop, because rigidbodies are put to sleep to save CPU time if they aren't moving.

Comment
Add comment · Show 5 · 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 Thom Denick · Feb 03, 2011 at 12:14 AM 0
Share

I have seen the problem he is describing about OnCollisionExit not triggering, though. Is it possible the exit is occurring on a sleeping object? I created a kind of lengthy workaround for this issue, increasing sleep time would fix it?

avatar image Eric5h5 · Feb 03, 2011 at 01:42 AM 0
Share

@Smorpheus: No, there's a regression in Unity 3 compared to Unity 2 with regards to OnCollisionExit not firing when it should.

avatar image Dmitry Pyalov · Feb 03, 2011 at 09:11 PM 0
Share

Yes, it seems like this. A little hack did the trick. Just add zero force to the body on every FixedUpdate.

avatar image Eric5h5 · Feb 03, 2011 at 09:27 PM 0
Share

If you want to prevent sleeping, you can check rigidbody.IsSleeping() and if true call rigidbody.WakeUp().

avatar image Dmitry Pyalov · Feb 04, 2011 at 09:31 AM 0
Share

Won't work, because on FixedUpdate stage the body is not sleeping yet but OnCollisionStay is not fired then. On the next FixedUpdate it is already sleeping, so I can't track this event. It seems, that the body goes to sleep just after FixedUpdate and before OnCollisionStay.

The other problem is, OnCollisionExit is somehow not always called for each OnCollisionEnter contact.

avatar image
0

Answer by tertle · Feb 02, 2011 at 11:51 PM

Just a note which may or may not relate to your problem, but collisions will only trigger if you apply a force or use the move function, not if you set the position. Also needs to be moved in FixedUpdate to interact with kinematic rigidbodies.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

2D 360 degress platformer example needed 0 Answers

Newbie having problems with attaching cloth to a character. PLEASE HELP! 1 Answer

Does AddForce use Time.deltaTime or TIme.fixedDeltaTime or it depends on whether it is being used in Update() or fixedUpdate()? 2 Answers

Rotating a Rigidbody with Physics 1 Answer

hit.rigidbody.useGravity problem? 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