- Home /

# Mesh triangles don't match wireframe view?

So I have a mesh of a sphere made out of lots of fairly evenly shaped triangles. When I switch the scene view to "wireframe", I can easily see the triangles of my mesh.

I assumed that if I got the mesh.triangles, it would provide me with... those triangles I can see in wireframe view.

But that doesn't seem to be the case. As I loop through the triangles... the majority of the time, yes, it's giving me the three corners of a triangle, which I can find using my eyes looking at the wireframe mesh, if I find them on the mesh.

But once in a while mesh.triangles is giving me three vector3 positions that do NOT make up any sort of triangle at all, at least none that I can see looking at the wireframe. It's usually three vertices that are fairly close together, but sometimes they form more like a line, not a triangle. Other times, one of the three points will jump a whole triangle away, and there is no way that vertex is part of any triangle, there is no "edge" that connects that vertex to the others, it's not a valid triangle on the mesh, at least not according to what I see looking at the wireframe.

Can anyone explain why mesh.triangles is giving me this?

Here's my code:

```
Mesh mesh = transform.GetComponent<MeshCollider>().sharedMesh;
int[] tri = new int[mesh.triangles.Length];
Vector3[] ver = new Vector3[mesh.vertices.Length];
mesh.vertices.CopyTo (ver, 0);
mesh.triangles.CopyTo (tri, 0);
int vertlen = ver.Length;
int trilen = tri.Length;
int[] UnfinishedVerts_Index = new int[vertlen];
for (int a = 0; a <= vertlen - 1; a++) {
UnfinishedVerts_Index[a] = a;
}
for (int triangle_loop = 0; triangle_loop <= UnfinishedTriangles_Index.Length - 1; triangle_loop += 3) {
int TriVert_Index1 = tri[UnfinishedTriangles_Index[triangle_loop + 0]];
int TriVert_Index2 = tri[UnfinishedTriangles_Index[triangle_loop + 1]];
int TriVert_Index3 = tri[UnfinishedTriangles_Index[triangle_loop + 2]];
Vector3 Trivertex1 = ver[TriVert_Index1];
Vector3 Trivertex2 = ver[TriVert_Index2];
Vector3 Trivertex3 = ver[TriVert_Index3];
}
```

In the above code, Trivertex1, Trivertex2 and Trivertex3 should be the three vertices of the triangle. And they usually are. But once in a while one of them jumps a whole triangle away, or something like that.

I thought it was my mesh, like maybe my mesh was "bugged". But, I can clearly see the triangles on my mesh when I look at it with wireframe view. If it was my mesh, I should see an "edge" connect to these out-of-place vertices, right? I see only perfect triangles in wireframe view. And mesh.triangles isn't giving me the same perfect triangles I see.

Each element in $$anonymous$$esh.triangles gives you the indices into the vertices array for a given triangle. Please post the code you use for inspecting the vertices of a particular triangle - sounds like there might be a bug in it.

### Your answer

### Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

### Follow this Question

### Related Questions

Connecting flatshaded vertices 0 Answers

Understanding verts and triangles in Unity 1 Answer

Changing Y Value in Vertex Array? 1 Answer

Does mesh.triangles also return a copy of the triangle array? 1 Answer

Optimized vertex manipulation 1 Answer