- Home /
Question by
reissgrant · Aug 31, 2010 at 12:50 AM ·
verticesvertex
drawing vertices
I'm drawing vertices in the editor as gizmo spheres however the positions are always stationary, never moving when I adjust the position or scale of the object it's attached to. Is there something I'm missing?
void OnDrawGizmosSelected () {
MeshFilter selectedMeshFilter = (MeshFilter)gameObject.GetComponent("MeshFilter");
Mesh mesh = selectedMeshFilter.mesh;
Vector3[] vertices = mesh.vertices;
Color[] colors = new Color[vertices.Length];
for (var i = 0 ; i < vertices.Length ; i++){
Gizmos.DrawSphere (vertices[i], vertexSize);
}
mesh.vertices = vertices;
mesh.RecalculateBounds();
}
Comment
Best Answer
Answer by Jessy · Aug 31, 2010 at 01:27 AM
Yes. The Transform component equates to a matrix that gets applied to vertex data. Changing values in the Transform will not update the vertices array of a mesh, nor would you want it to. Instead, use Matrix4x4.TRS, with the values from the Transform, and apply that to the vertices array that you get.
Your answer
![](https://koobas.hobune.stream/wayback/20220613072408im_/https://answers.unity.com/themes/thub/images/avi.jpg)