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
3
Question by Tasarran · Dec 09, 2011 at 05:59 PM · verticesmeshcollidermesh collider

Modify Mesh Collider when modifying vertices?

I am modifying vertices on some objects in my scene, but if they have a Mesh Collider on them, that collider retains the original shape.

I think this is because it is still tied back to the original Mesh, which is in essence, a prefab for the mesh component.

Is there a way to make a unique collider for a modifed mesh?

Comment
Add comment · Show 3
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 paul100k · Dec 16, 2011 at 09:53 AM 0
Share

Hey guys...

I´m having a problem which is quite the same. BUT the Problem about it, is that I have to update the collider shared $$anonymous$$esh every frame (at least 30 times per second)...

Do you have any idea how to get this effect ?! The vertices count is around 2000.

The Project is about: I´m moving my vertices of the terrain in Y-Space. $$anonymous$$y Objects have to be on top of the mesh so they won´t fall through the terrain. If the update is to slow they will fall down. :( You know what I mean ?!

I thought about using iTween but I´m not sure about the technique ob this... does it help me ?! So... does it use vertices to calculate the movement (this would solve everything!) or is it just using the meshcollider (if so ... my problem is still there)

thanks a lot !! :)

avatar image Tasarran · Dec 16, 2011 at 05:41 PM 2
Share

Please delete this non-answer.

avatar image aida12_99 · Mar 29, 2016 at 05:02 AM 0
Share

@Lka, @defaxer @Statement: None of the above solutions worked for me :-((

I have a rope hanging between two poles. The rope has physics properties and thus the $$anonymous$$eshCollider must be as dynamic as the rope. But, the $$anonymous$$eshCollider stays statically like a straight line between the poles. I have tried all solutions above and none of them worked!

Any help will be appreciated!

6 Replies

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

Answer by Bunny83 · Dec 09, 2011 at 10:02 PM

Shouldn't setting MeshCollider.sharedMesh to your new mesh be enough? ;)

Comment
Add comment · Show 4 · 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 Tasarran · Dec 09, 2011 at 11:22 PM 0
Share

This does the trick, too...

I wish I could have two answers, but this one does a slightly more direct job, so I have to give this one the extra +1.

avatar image Statement · Dec 10, 2011 at 01:01 PM 0
Share

Actually, I tried replacing my code with this approach. The problem is that the collision mesh won't update. I am reusing a mesh, not creating a new one. $$anonymous$$aybe the shared$$anonymous$$esh property doesn't rebuild the collision model if the same $$anonymous$$esh reference is being set (even if the contents of that mesh differ from the last time). @Tasarran, did you verify that this solved the issue on your end? Then I can't figure out what else I might be doing wrong. Just setting shared$$anonymous$$esh to the same mesh won't update collision for me :/

avatar image Bunny83 · Dec 11, 2011 at 03:26 PM 0
Share

@Statement: Yep, that could be. I wish Unity would provide an "Update / Commit" function for such cases. At the first glance it's nice if something happens automatically, but it only reduces the possibilities or can get you in trouble since you can't specify when you want the update happen.

avatar image Tasarran · Dec 12, 2011 at 04:05 AM 0
Share

@Statement Yes, it works fine for me, but I am not changing the topology or number of points in my mesh, just moving them around.

I think since (it seems) you are punching holes and adding/removing points, you might be a special case...

Your way did work for me, too, but like I said, I had to give the nod to Bunny's answer for being one step less :)

avatar image
5

Answer by Lka · Dec 09, 2012 at 12:58 AM

setting meshcollider=null and then meshcollider=mesh seems to work in unity 4

             mc = go.GetComponent<MeshCollider>();
             if(mc==null)
                 mc = (MeshCollider) go.AddComponent (typeof(MeshCollider));
             else
             {
                 mc.sharedMesh = null;
                 mc.sharedMesh = mesh;
             }
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 Excrubulent · Mar 01, 2014 at 12:48 PM 0
Share

Thanks, this is a cleaner method than destroying and remaking the $$anonymous$$eshCollider object. I'm assu$$anonymous$$g it has less overhead, too.

avatar image emathew · Jan 16, 2018 at 07:34 PM 0
Share

in mc.shared$$anonymous$$esh = mesh; What does mesh equal?

avatar image
3

Answer by Statement · Dec 09, 2011 at 06:19 PM

Yes, but it's slow. I used to do this when I was using mesh colliders for my voxel terrain. If anyone else have a better answer, then I'll vote you up!

 void Update()
 {
     if (chunk.Rebuild(mesh))
     {
         Debug.Log("Rebuilt mesh");
         DestroyImmediate(collider);
         gameObject.AddComponent<MeshCollider>();
     }
 }

Basically, you need to destroy the collider and add it back on again.

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 Tasarran · Dec 09, 2011 at 07:06 PM 0
Share

Thanks! I don't $$anonymous$$d if it's slow, I'm only doing it once, at startup. $$anonymous$$ight be a 'load lag', but that's a non-issue as far as game play goes.

avatar image Tasarran · Dec 09, 2011 at 08:09 PM 0
Share

Works perfectly, thanks again! Adding an up vote for the quick and useful advice.

avatar image
2

Answer by defaxer · May 27, 2015 at 12:38 PM

Not really an elegant solution, but disabling and then enabling MeshCollider works fine for me

Comment
Add comment · Show 1 · 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 SkywardRoy · Sep 14, 2019 at 11:29 AM 0
Share

Compared to all the other options this still seems to be the best solution right now.

avatar image
1

Answer by keithkeith · Nov 25, 2014 at 12:00 AM

Just nulling the mesh and resetting it doesn't seem to work anymore. I had to destroy the whole collider and recreate it.

 DestroyImmediate(this.GetComponent<MeshCollider>());
 var collider = this.AddComponent<MeshCollider>();
 collider.sharedMesh = myMesh;
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
  • 1
  • 2
  • ›

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

CameraRig Rigidbody going through collider 1 Answer

Move Objects arround Vertices Array 2 Answers

MeshCollider (concave) doesn't trigger OnCollision functions 0 Answers

Mesh Collider not work with procedural mesh 0 Answers

How can I do drilling using mesh colliders 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