- Home /
Mesh.vertices are all 0?
I made this mesh in blender, and imported it into unity as an fbx. The vertices array has a bunch of verts on it, but they are all 0, 0, 0.
private void OnGUI()
{
if (GUILayout.Button("test")) {
plane = GameObject.Find("testPlane");
mesh=plane.GetComponent<MeshFilter>().sharedMesh;
for (int i=0; i<mesh.vertices.Length; i++) {Debug.Log(mesh.vertices[i]); }
}
Why would it be doing this?
Also this is an editor script in the editor folder.
public class editorTest : EditorWindow
Answer by Bunny83 · May 02, 2020 at 10:50 AM
First and foremost never ever execute such a loop -.-
Each time you read the vertices property of the mesh class you will create a new copy of the vertices array and the vertices are copied from native code into the managed code array. Currently you create a new copy of your vertices array two times each iteration. So always cache that array:
Your next issue could be that since the default ToString override of Vector3 rounds the output to 1 decimal place you might not see your actual numbers if you created a very small mesh. This could easily happen when you imported the mesh with a very small scaling factor. So try printing the vectors with a higher precision. "F7" should be enough for most cases.
mesh=plane.GetComponent<MeshFilter>().sharedMesh;
var vertices = mesh.vertices; // read it once
for (int i=0; i < vertices.Length; i++)
{
Debug.Log("Vertex #"+i+" = " + vertices[i].ToString("F7"));
}
If they are still all (0, 0, 0), do you actually see the mesh in the scene? How large does it appear in the scene? When click on the mesh field of the MeshFilter in the inspector, Unity should highlight the actual source mesh in the project so you can inspect the actual mesh and see its stats in the inspector. How many vertices / triangles does the mesh have?
Thanks, the verts weren't exactly 0, but were really small numbers. It was because my fbx had 100 scale on it. I got the scale to 1 and everything is working now.
Your answer
Follow this Question
Related Questions
Why vertex positions appear (0.0, 0.0, 0.0) ? 1 Answer
Creating a mesh for an overview map 0 Answers
Unidirectional slicing algorithm of a mesh 0 Answers
Mesh triangles don't match wireframe view? 0 Answers
Mesh Vertices Welding 0 Answers