Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 WavyRancheros · Jul 08, 2014 at 12:02 PM · coroutinelagmeshcollidermeshfiltersharedmesh

Changing sharedMesh in MeshCollider causes lag

Hi,

I make changes to my mesh, and want to update the MeshCollider after I'm done. The problem is that it causes a lag of about 1-2 seconds. The whole program freezes for that time, I cannot move the camera, nothing.

I tried to circumvent this issue by putting the code for the mesh replacement in a Coroutine. But that doesn't have any effect.

If have no problem with the update taking 2 seconds. But I need to find a way to react to it (like displaying a text "Updating..."), and I still want to be able to move the camera and do other things while it is updating the mesh.

Here is the code snippet I'm using. The coroutine is called in Update when a mouse button is clicked and a raycast hits the object (that updates currentMeshFilter).

 IEnumerator ApplyMeshColliderCoroutine(){
     applyingMesh = true;
 
     if(currentMeshFilter != null){
         GameObject go = currentMeshFilter.gameObject;
         MeshCollider mc = go.GetComponent<MeshCollider>();
 
         mc.sharedMesh = null;            
         mc.sharedMesh = currentMeshFilter.sharedMesh;                
     }
 
     currentMeshFilter = null;
 
     applyingMesh = false;
     yield return null;
 }

I did some tests taking the time using System.DateTime (because Time.time didn't work), and what causes the lag is the line

 mc.sharedMesh = currentMeshFilter.sharedMesh;

Any help greatly appreciated.

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
0

Answer by Tony-Sparrow · Nov 18, 2015 at 01:53 AM

  • I have same issue, and I find this

It is recommended to use this function only for reading mesh data and not for writing, since you might modify imported assets and all objects that use this mesh will be affected. Also, be aware that is not possible to undo the changes done to this mesh.

check out these link

http://answers.unity3d.com/questions/63313/difference-between-sharedmesh-and-mesh.html

http://docs.unity3d.com/ScriptReference/MeshFilter-sharedMesh.html

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

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

Mesh Collider with model that uses armature. 0 Answers

Does collider size affect performance? 1 Answer

Replace MeshFilter mesh by a other mesh in Editor 1 Answer

difference between sharedMesh and Mesh 1 Answer

Finding sharedMesh users. 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