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 Excrubulent · May 14, 2014 at 03:31 AM · optimizationmeshcollidermesh-deformation

How can I speed up assigning a mesh to a MeshCollider?

I am generating large meshes, getting close to Unity's ~65535 vertex limit. This doesn't take a long time - in fact, I can modify them in realtime.

However, when I call:

 meshCollider.mesh = generatedMesh;

suddenly the whole program freezes for several seconds while this gets done.

Now, I'm assuming there's a lot of optimisation going on, like assigning vertices to an octree, and so on, but I'm wondering if there's any way to speed this up at all.

Alternatively, running the process in the background might work, since I don't need the collision geometry immediately after generating the mesh, but I'm not sure if this is possible in Unity.

Also, settings for the MeshCollider are:

 Is Trigger: false
 Material: none
 Convex: false
 Smooth Sphere Collisions: true

It can't be convex, because it's a hollow shape, and smooth sphere collisions are on because it needs to be as smooth as possible, since it's a driving surface.

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 Cherno · May 15, 2014 at 12:41 AM

When generating meshes at runtime, it's most often the part where the mesh gets assigned to the collider that is taking the longest time. There are no simple workarounds, it's just that way and not a bug. Consider smaller chunks and spreading their generation out over several frames to help speed thigns up.

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 Excrubulent · May 15, 2014 at 01:19 AM 0
Share

Okay, thanks. Probably the best solution is to throw up a loading bar whenever they're needed. It'll happen when switching from an editor mode to playing, so it should at least make sense to the user.

avatar image
0

Answer by zharik86 · May 14, 2014 at 07:08 AM

I faced such problem when worked over mazes. Walls was too much and they should be connected in one mesh. Then to use the MeshCollider component for this mesh. Time of generation of mesh isn't enough, but here creation of a collider took some seconds. The acceptable decision for abbreviation of time to find it didn't turn out. It was necessary to do a certain pause with a text about loading that not bad looked. However, in case of the test on the mobile device (Sony Experia Tablet Z) about 7 mesh with quantity of peaks ~ 65k loading about 10 seconds. Therefore if you have not any random generated mesh, it is best of all to use composite colliders (for example, some BoxCollider).

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 Excrubulent · May 15, 2014 at 01:11 AM 0
Share

Thanks for the answer, although if you've run it through a translator I'm afraid it's made a mess of most of your sentences. I'm afraid composite colliders would destroy the smoothness of the mesh too much.

avatar image Cherno · May 15, 2014 at 01:39 AM 0
Share

There are also nifty algorithms to create a seperate mesh for the meshcollider that has only as many vertices as needed by finding faces as large as possible. This would also speed things up since the resource-heavy part (assigning mesh collider) now deals with a mesh that has a smaller (possibly $$anonymous$$imum) number of vertices.

Check the "After playing $$anonymous$$inecraft..." thread on the forums.

avatar image Excrubulent · May 21, 2014 at 02:48 AM 0
Share

@Cherno I'm afraid that's not really going to be possible, since the geometry of the mesh is designed around how it works as a collider. There aren't any flat surfaces to merge into a single face.

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

22 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

Related Questions

Accessing mesh vertices is extremely inefficient; any workarounds? 0 Answers

FBX mesh collider causing iOS to crash 2 Answers

Whether Collider need be combined? 0 Answers

Is it better to use Mesh Colliders on Mass Projects or Box Colliders? 2 Answers

Ray cast not hitting the backside of mesh collider attached to a spherical mesh object 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