I want to change the mesh of a gameobject which is the child of another gameobject. I locate the mesh, copy it, change it, clear the old mesh and replace it, as described in the script reference but the changes don’t seem to take effect.
Is it because it’s a child object? Here’s my code briefly, I feel like it should work:
Transform parentTransform; Transform childTransform; Mesh mesh; Vector3 vertices; Vector3 vert; Vector2 uv; int triangles; ... childTransform = parentTransform.Find(childname) mesh = childTransform.gameObject.GetComponent<MeshFilter>().mesh; vertices = mesh.vertices; uv = mesh.uv; triangles = mesh.triangles; vert = vertices; vert.y += 5; // Change y of a single vert vertices = vert; mesh.Clear(); // Clear old mesh mesh.vertices = vertices; // Assign new vertices with that one altered point mesh.uv = uv; mesh.triangles = triangles; childTransform.gameObject.GetComponent<MeshFilter>().mesh = mesh; // Not sure if necessary