Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
0
Question by jjey225 · Sep 19, 2019 at 02:12 PM · optimizationmesh colliderupdating

Updating Mesh Collider causes lag

I created a plane that the player can modify, but updating the mesh collider causes a significant drop in frames. I use this code to update collider:

 hitTransform.GetComponent<MeshCollider>().sharedMesh = hitTransform.GetComponent<MeshFilter>().sharedMesh;

Is there any way to optimize it?

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 mikedg1 · Sep 20, 2019 at 12:43 PM 0
Share

A permanent drop in frames? Or a drop while that code executes (guessing less than a second)?

avatar image jjey225 mikedg1 · Sep 21, 2019 at 08:25 AM 0
Share

No, only when executing the code - the one above.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Arano · Sep 19, 2019 at 02:49 PM

you could save a reference to the mesh/collider components, could help but i don't think it this can be the problem in your case.

 MeshCollider collider;
 MeshFilter filter;
 void start() {
 collider = hitTransform.Getcomponent<MeshCollider>();
 filter = hitTransform.Getcomponent<MeshFilter>();
 }
 // your line of code:
 collider.sharedMesh = filter.sharedMesh;
 



this is the only thing i can see right away you could improve, not sure if changing a meshCollider has any special effects on framerate.. did u try use the profiler to figure out what might cause this?

Ive done pooling tests with colliders before and other than wheel colliders exponential performance hits were taken when removing a group of 2d colliders or adding a group of 'normal' colliders

u might want to disable the collider before you make changes and enable it again when you are done (using a temporary copy maybe?)

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 jjey225 · Sep 19, 2019 at 03:11 PM 0
Share

The frame drops are clearly visible when the plane has more than 10,000 vertices. This is how the profiler looks like: alt text And yes, I am sure that modifying $$anonymous$$esh Collider causes lag because by disabling collision refresh in the controller from terrafor$$anonymous$$g no frame drops occur.

cap489145.png (198.6 kB)
avatar image
0

Answer by hexagonius · Sep 19, 2019 at 02:59 PM

What really helps is the brand new Unity 2019.3 bake offloading capability: https://docs.unity3d.com/2019.3/Documentation/ScriptReference/Physics.BakeMesh.html

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 jjey225 · Sep 19, 2019 at 03:16 PM 0
Share

Sounds good, but the question is: Will I not have to bake it after every change in the mesh? If so, I doubt it would 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

120 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Mesh collision and raycast working differently after updating to 2021 0 Answers

Releasing an app update problems 1 Answer

Possible Memory Leak on Asset Server Update 0 Answers

Updating Editor with runtime updated Text Assets 1 Answer

Ways to minimize Object.stelemref() calls (low level) 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