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 newborne · Sep 22, 2012 at 11:11 AM · collidermeshcoroutineadd

adding mesh collider in run time slow?

i would need an advice about adding mesh colliders in run time. this makes size of the build much smaller but it takes some time to add a collider, especially mesh colliders.

i wanted to do it in the coroutine but it somewhat hangs, but without coroutine it freezes. here is the code to add mesh colliders to transforms:

 void Prepare(){
         
     StartCoroutine(StartPrepare());
 }

 IEnumerator StartPrepare()
 {
         
    Transform[] objects = prefabToPrepare.GetComponentsInChildren<Transform>();
                 
    for(int i = 0; i < objects.Length; i++)
    {
         if(objects[i].gameObject.renderer)
       {
         objects[i].gameObject.AddComponent<MeshCollider>();
         Debug.Log("i: " + objects[i].name);
         yield return null;    
       }
    }
 }


i am doing something wrong here, uncommenting add mesh collider line debug statements are printed, adding box collider is much faster. meshes are not that high poly...?

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

3 Replies

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

Answer by Fattie · Sep 22, 2012 at 01:54 PM

It simply takes a long time to "import" as it were, a mesh.

(Please note .. as Eric critically points out below, the problem is the mesh collider, not the mesh-that-draws-stuff.)

You "just can't" - that's it. You're doing nothing wrong, it's just an inherent limitation of today's pipeline, hardware and software.

If you build something dynamically, say a Dragon, that's great. At start-up time or between scenes you can "import" that new mesh you've created dynamically.

But the current state of the art 3D game pipeline - you just can't "import" your new mesh in real time. That's that.

To be clear, the actual calculation time for you to make a mesh is nothing. The problem is "importing" it to the pipeline. (To be clear, issues like foreach, coroutines, etc, are totally irrelevant.)

There are many long-winded discussion about this basic limitation on this site, eg

http://answers.unity3d.com/questions/315059/how-to-improve-performance-while-generating-extrud.html

"Basically putting new mesh in to a scene is ... slow ! it just takes a long time to cycle in the new mesh. That's that really."

Hope it helps, sorry for the bad news ! :O

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 Eric5h5 · Sep 22, 2012 at 02:08 PM 3
Share

Putting a new mesh in the scene is not slow. Adding a mesh collider, however, is, because there are some heavy pre-processing calculations done by PhysX, so that it will perform faster.

avatar image
1

Answer by RunSwimFly · Feb 26, 2013 at 04:35 AM

Late answer but I found that chopping my meshes up before adding a mesh collider to them significantly reduced the overall time required. In my case this automatic subdivision was relatively simple as it was for user generated heightfields on a regular grid.

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 vikingfabian-com · Jun 30, 2014 at 06:08 PM

My solution was to recycle the GameObjects

  • put them in a Stack

  • Set Renderer.Enabled to false

  • pop the stack when you need an object, if the stack is empty you create a new GO.

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

15 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

Related Questions

Detecting whole gameobject, not just its collider 1 Answer

mesh colliders moving when i press play 1 Answer

how do i make my modle solid? 2 Answers

Adding a collider to array 1 Answer

collision between a rigidbody and a mesh collider not working 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