# Gizmos.DrawMesh does not render anything

I would like to draw a procedural mesh as a gizmo:

Gizmos.DrawMesh(mesh);


however this does not render anything no matter what. I can confirm that the mesh in question is a correct one by both GetComponent<MeshFilter>().mesh = mesh assigning it to Renderer and rendering it using default material and Gizmo.DrawLine drawing it edge-by-edge.
No error are logged in debug window, setting position or flipping triangle orientation has no effect neither. Version of Unity is 5.6.2f1. Am I missing something?

void Start ()
{
GetComponent<MeshFilter>().mesh = mesh; //renders without any problems
}

void OnDrawGizmos()
{
Gizmos.color = Color.red;
Gizmos.DrawMesh(mesh);//nothing rendered
//renders without any problems
for (int i = 0; i < mesh.triangles.Length / 3; i++)
{
Gizmos.DrawLine(mesh.vertices[mesh.triangles[i * 3 + 2]], mesh.vertices[mesh.triangles[i * 3]]);
Gizmos.DrawLine(mesh.vertices[mesh.triangles[i * 3]], mesh.vertices[mesh.triangles[i * 3 + 1]]);
Gizmos.DrawLine(mesh.vertices[mesh.triangles[i * 3 + 1]], mesh.vertices[mesh.triangles[i * 3 + 2]]);
}
}

• I'm not able to reproduce this issue with meshes I've tried so far - they all render correctly with gizmos as expected. Can you try it with variants on the problem mesh to see if there's a particular quirk to the mesh you're using that the gizmo renderer rejects? – DMGregory Oct 14 '17 at 22:31
• @DMGregory It appears to be broken for every mesh not just particular one, e.g. even for trivial meshes like [5.0,4.0];[-5.0,4.0];[-5.0,-4.0];5.0,-4.0] with indices 3,2,1,1,0,3. Also forgot to mention - it is 2D (ortho camera) if that ever plays role. – wondra Oct 15 '17 at 1:04
• It's working with every mesh I've tried, including built-in primitives and triangle meshes generated at runtime. Is it possible your winding order is causing it to be rejected as a back-face, or that it's getting drawn off-screen / too close for the near plane? Otherwise this might be a Unity bug or a corruption of some kind. See if you can DrawMesh with a primitive cube in a new project to test whether there's something amiss with your editor installation. – DMGregory Oct 15 '17 at 1:14
• @DMGregory it was the normals - not that I did not try adding them but flipping orientation was also required. Never tried combination of both. The fact that the default amterial does not require normal did not contribute to finding the problem neither. This might be a silly error, but still I feel at least some warning like "error: unassigned normals" should be produced for a mesh being rendered, making the API more user friendly. – wondra Oct 15 '17 at 12:35

mesh.normals = Enumerable.Repeat(Vector3.forward, mesh.vertices.Length).ToArray();

mesh.RecalculateNormals();