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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by SGStino · Jul 06, 2014 at 06:23 PM · c#physicsrigidbodycollider

Adding many BoxColliders

I'm trying to add about 30 box colliders at run-time.

Doing this with a for loop and gameObject.AddComponent() results in a noticeable lag-spike of 0.20 seconds.

Is there a way to group this to improve performance? I used to do this in my engine with BepuPhysics by creating the Compound in a separate thread, and dispatching the result back to the game thread to update the physics object. But since unity's API isn't thread-safe, I can't do this. But I also have no idea how to do it differently.

Comment
Add comment · Show 2
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 PProductions · Jul 06, 2014 at 07:01 PM 0
Share

why not build a mesh at runtime of all the boxes you need and add it to a single mesh collider?

avatar image SGStino · Jul 06, 2014 at 07:20 PM 0
Share

Shouldn't a mesh collider be slower than a box collider? And if I recall correctly: mesh-mesh collisions don't work in unity?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by chillersanim · Jul 06, 2014 at 07:28 PM

Adding a component is ressource intensive.
That is because the component has to be registered in a global dictionary, and a collider has to be registered in the physics to.

I would recommend you not to use box colliders when you need so many, but instead create a mesh, that covers the used space and use a mesh collider.
You can either generate the mesh by code or make a mesh in your favourite 3D application.

Also try to replace many simillar components with one component, even if the replacement component is more complex.
In general, it costs more performance to iterate through all components than to calculate that one component.

Greetings
Chillersanim

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 SGStino · Jul 07, 2014 at 11:19 AM 0
Share

That would be an option, but i'd have to split the mesh in convex parts, that would most likely end up in the same order of colliders. as the current box collider approach.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Rigidbody.SweepTest Hit Trigger Colliders 0 Answers

Distribute terrain in zones 3 Answers

C# Check if Collider2D[] Doesn't contain Scripted GameObject 1 Answer

Applying proper drag and center of mass for a vehicle 1 Answer

RigidBody.MovePosition seems jerky in movement 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