- Home /
How do i replace a Mesh Filter??
Hello how do i replace a mesh filter on a cube via code(C#)??
Answer by villevli · Sep 23, 2016 at 05:59 PM
You probably don't want to replace the whole MeshFilter component but the Mesh assinged to it. Just Assing a new mesh to the MeshFilter.
GetComponent<MeshFilter>().sharedMesh = mesh;
Thanks :D. but whats the difference between sharedmesh and mesh?
Sharedmesh: 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.
Setting the mesh will only change the mesh of the current $$anonymous$$eshFilter, but not the asset behind it.
Also, when setting a mesh, make sure to first Clear the mesh of the $$anonymous$$eshFilter, then create a $$anonymous$$esh by using $$anonymous$$esh m = new $$anonymous$$esh(); now modify mesh m and set it to the $$anonymous$$eshFilter by using GetComponent().mesh = m;