Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
0
Question by samyslee · Apr 04, 2019 at 09:55 PM · meshcollideroncollisionexit

updating MeshCollider, but OnCollisionExit() not working

I need to dynamically update my collier. OnCollisionEnter() and OnCollisionStay() were called when the collider enters a Riggybody, but why OnCollisionExit() won't be called when the collider exits Riggybody?

 void Update()
 {
     //Update MeshCollider
     MeshFilter mf = gameObject.GetComponent<MeshFilter>();
     gameObject.GetComponent<MeshCollider>().sharedMesh = mf.sharedMesh;
 }
 void OnCollisionEnter()
 {
     Debug.Log("OnCollisionEnter called.");
 }
 void OnCollisionStay()
 {
     Debug.Log("OnCollisionStay occuring.");
 }
 void OnCollisionExit()
 {
     Debug.Log("OnCollisionExit called.");
 }
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 Chris333 · Apr 05, 2019 at 08:29 AM 0
Share

You are missing the collision parameters in your example.

avatar image Bunny83 Chris333 · Apr 05, 2019 at 10:13 AM 1
Share

He's not missing the parameter, he has omitted the parameter which is possible for those callbacks:

If you don't use collisionInfo in the function, leave out the collisionInfo parameter as this avoids unneccessary calculations.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Bunny83 · Apr 05, 2019 at 10:21 AM

What you do here is generally a bad idea. First of all Unity's phyics system is a rigidbody simulation. A rigidbody is a rigid body. So one object doesn't change it's shape. Any object that is moving / rotating has to have a rigidbody attached. Colliders without a rigidbody component must never be moved / rotated / changed.


I know in the past it wasn't possible to update a MeshCollider like that. Maybe this got fixed. Anyways recalculating / recreating a meshcollider every frame is very bad for performance and certainly won't produce any realistic rigidbody movement.


For moving objects that should not be controlled by the physics engine but are moved by script need a kinematic rigidbody. Note that for collisions to happen one of the two colliders need to belong to a non-kinematic rigidbody. So two kinematic rigidbodies can't collide with each other.

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 Understainding · Sep 29, 2020 at 03:29 PM

OnCollisionEnter is executed when an object enters the current mesh. OnCollisionStay is executed as the object remains in. As soon the mesh collider gets modified, the collider internal data changes.

Therefore the it does not remember what is inside so it will not call OnCollisionExit.

Console Debug Log is persistent and does not reflect current internal state of the collider.,This is probably because you rebuild the mesh any memory of it gets erased. That is, as an obstacle enters the mesh, It triggers OnCollisionEnter, as long as the collider is not modified then exexutes OnCollisionStay. But as soon, as it is modified it stoops. For it is, a new [mesh] collider all together.

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

105 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Mesh colliders not working on FBX imported buildings 1 Answer

Small mesh colliders or a single big mesh collider 0 Answers

imported mesh collider won't line up with original mesh 2 Answers

Can I check collision with non-convex mesh colliders? 0 Answers

Terrain - Meshcollider crashes unity 0 Answers


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