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 Aubrey Hesselgren · Oct 21, 2010 at 09:43 AM · collisionmeshprocedural

Collision on generated mesh

According to the documents, mesh colliders are only constructed when the mesh is placed into the scene.

Is it possible to force a collider component to construct itself based on a mesh filter which you yourself have constructed at runtime? i.e. if geometry changes?

I.e. if I were to make a parametric spiral mesh, for example, and wanted to be able to tweak how many degrees it generates through at run time, and then wanted the result to be collidable, how would I go about that?

If a prefab was instantiated into the scene, and the geometry was constructed in the "Start()" function, would that be early enough to let the mesh collider construct itself?

Or should I add a mesh collider to the game object at runtime after the mesh data is set up?

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

1 Reply

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

Answer by duck · Oct 21, 2010 at 11:26 AM

All you need to do is add the mesh collider component to the same object after you've finished generating the procedural mesh itself. It's fine if it's all in the Start() method. For example:

void Start() {

 // create new Mesh Filter & Mesh objects
 var meshFilter = AddComponent<MeshFilter>();
 var mesh = new Mesh();

 // set up mesh
 mesh.name = name;
 mesh.vertices = myVerts;
 mesh.triangles = myTris;
 mesh.RecalculateNormals();
 meshFilter.mesh = mesh;
 mesh.RecalculateBounds(); 

 // add collider! 
 AddComponent<MeshCollider>();

}

Comment
Add comment · Show 3 · 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 Aubrey Hesselgren · Oct 21, 2010 at 11:41 AM 0
Share

Thank you!

There's no need to point the $$anonymous$$eshCollider at the actual mesh, after adding it, or...?

avatar image duck ♦♦ · Oct 21, 2010 at 12:17 PM 0
Share

No, I guess unless you specifically tell it to use another mesh, it uses the same mesh as the $$anonymous$$eshFilter object.

If you want to make a lower-res proxy mesh for the collision (while using a higher res mesh for the renderer), you'd have to look into that more closely - or just use separate gameObjects for each :)

avatar image Aubrey Hesselgren · Oct 25, 2010 at 09:55 AM 0
Share

Thanks again duck! Really appreciate the help!

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

No one has followed this question yet.

Related Questions

minimize vertex artifacting for procedural mesh manipulations - vertex collision same object? 0 Answers

Procedural Geometry doesn't collide.. 1 Answer

Best approach for collision in shape combination game? 0 Answers

Having an array of points(vector2), how do I create a 2d terrain? (new to unity) 2 Answers

Combine common surfaces 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