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
2
Question by ZorNiFieD · Apr 12, 2013 at 03:21 AM · mesh collider

meshcollider enable/disable

I have an odd issue. I am generating mesh colliders in script. The script works, the gameobject in the hierarchy has a mesh collider and a meshfilter.

The problem is, the collider doesn't function unless I manually disable the mesh collider then re-enable it using the inspector. Once I do that, the collider shows up in scene view (if i have disabled mesh renderer) and works how it's supposed to.

I tried to simulate in script by simply setting the enabled property on and off, but no go. Still works the same, I have to open the inspector, disable the collider, then re-enable it for it to function/display.

Any reason why this is happening?

Comment
Add comment · Show 1
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 MarshallN · Nov 21, 2017 at 09:21 PM 0
Share

I know this is an old question, but the same thing just started happening to me. Nothing about these object have changed since they worked, but now the colliders don't collide with my raycasts until I manually toggle them in the inspector. If anyone has a solution, I'm all ears.

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by MarshallN · Nov 21, 2017 at 10:19 PM

Alright, so this is a weird fix for a weird bug, but here goes: When I was instantiating the object with the MeshCollider, I enabled the MeshCollider in script just before I changed the object's parent, localScale, and rotation. When I moved the MeshCollider enable after those lines, it worked just fine. Ex:

 heldObject.transform.position = wireframe.transform.position;
 heldObject.GetComponent<MeshCollider>().enabled = true; // Colliders didn't work in this case.
 heldObject.transform.parent = null;
 heldObject.transform.localScale = Vector3.one;
 heldObject.transform.eulerAngles = wireframe.transform.eulerAngles;

But if I did it the other way 'round, like this:

 heldObject.transform.position = wireframe.transform.position;
 heldObject.transform.parent = null;
 heldObject.transform.localScale = Vector3.one;
 heldObject.transform.eulerAngles = wireframe.transform.eulerAngles;
 
 heldObject.GetComponent<MeshCollider>().enabled = true; // Here, it works.

Then it works just fine, with no weird manual toggling of the collider in the inspector.

Comment
Add comment · Show 2 · 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 Bonfire-Boy · Nov 21, 2017 at 11:23 PM 0
Share

Just curious - have you tried narrowing it down? i.e. seeing if it's all 3 of those lines that need to be before the enabling or just 1 or 2...

avatar image Hupman · Aug 30, 2018 at 04:18 AM 0
Share

Just ran into this. What a nightmare. Toggling enable / disable in code fixes it, so at least I don't have to do it in Inspector. Not a very gratifying fix. I suspect there is something else going on, but I can't pinpoint it.

avatar image
0

Answer by malkere · Apr 25, 2021 at 01:18 AM

I've had this in my game in the past and toggling enabled false then back to true worked in general... I'm running through a tutorial right now and am getting this with a scene object whose mesh I'm setting in runtime. So there's no positioning, parenting or anything, and the normal enabled toggling isn't working in frame 0 =[ I wrote a simple coroutine to disable the component, yield a frame, then re-enable it, and now it's working as intended... This is in 2019.4.14. Not sure why this seems to happen to some people and not others, but the disable/enable seems to be the only fix in some cases.

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

14 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

Related Questions

Mesh collider and Terrain collider 0 Answers

Default Mesh colliders are not working 1 Answer

Mesh Collider to a character and the maze? 3 Answers

How do i find the top of a mesh? 3 Answers

Procedural Generated mesh collider creates invisible walls after the first iteration 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