- Home /
Why does the Unity Editor display full mesh after I've programmatically removed vertices?
First - the situation: In an editor script I am performing a preprocessing step on a mesh in a scene to remove polygons that will never be rendered. To do this I:
- Figure out what triangles will possibly be visible within a mesh.
- Make a new mesh and assign it to the sharedMesh on the object I'm examining.
- Fill out a new set of vertices, normals etc that contain only the visible vertices.
- Fill out all submesh sets of triangles that are in the visible subset on the new mesh.
While both the editor and game now only render the polygons I've left around, selecting the modified gameobject then shows the original mesh (highlighted in green as normal) rather than the reduced one. If I examine the mesh in the asset window, it does correctly show the reduced mesh, and it has the correct vertext count and so on.
My question then is, why is Unity still displaying the original mesh when I select the relevant Game Object? Is there some link to the original asset from which the mesh came which I can't see? If that is the case, to truly create a reduced mesh, would I need to actually save out a new asset and create a totally new mesh based on that?
I don't know the answer for sure (hence this comment rather than an answer), but I suspect that you'd need to write out the mesh as a new asset. (For what it's worth, there's a 'create plane mesh' script on the wiki that shows how to do this.)
Answer by Bunny83 · Dec 28, 2010 at 05:04 AM
My guess is that you use a Meshcollider (the green lines are colliders). The Meshcollider component have also a link to a Mesh that should be used for collision detection. I'm sure if you set the Mesh variable of your Meshcollider to your new Mesh it should work. ps. Don't forget to call RecalculateBounds() and evt. RecalculateNormals() after changing the geometry.
Thanks! It was the collider. that was displaying the old mesh.
Your answer
Follow this Question
Related Questions
Standard Model Problems- after upgrade to 5.6.1 2 Answers
Editor lags when coming out of play mode...? 0 Answers
Displaying precision edges of a mesh at runtime? 0 Answers
Mirror vertices procedurally 2 Answers
Procedural "dripping" mesh? 1 Answer