- Home /
Question by
Arisstephenson · Jul 19, 2018 at 01:41 AM ·
gameobjectmeshcubevertex
Why aren't mesh vertex changes being applied?
I call this function at the start of my script. Why doesn't it work?
public void CreateMesh() {
if (cube != null) {
Destroy(cube);
}
cube = Instantiate(cubePrefab);
Mesh prim = cube.GetComponent<MeshFilter>().mesh;
cube.transform.position = currentPosition;
cube.transform.localScale /= 3;
cubeMesh = new Mesh
{
vertices = prim.vertices,
triangles = prim.triangles,
normals = prim.normals,
tangents = prim.tangents,
uv = prim.uv
};
cubeMesh.MarkDynamic();
cubeMesh.vertices[1] = Vector3.one * 2;
cube.GetComponent<MeshFilter>().mesh = cubeMesh;
}
Comment
change $$anonymous$$esh prim =
to $$anonymous$$esh cube$$anonymous$$esh =
?
See example in documentation for building mesh:
https://docs.unity3d.com/ScriptReference/$$anonymous$$esh.html
prim is the mesh asset which I don't want to directly edit, my goal is to create a copy of it so my changes aren't affecting the asset itself, but I will try that. Update: Still no affect on the mesh