# Procedural mesh comes out black in any shader

I wrote a script that Creates a mesh procedurally

        mr = gameObject.AddComponent<MeshRenderer>();
//
mf.mesh = new Mesh
{
vertices = GetVertices(),
triangles = GetTriangles()
uvs = UpdateUVMap();
};



(the mesh is a sphere for this example)

When played, all seems good except that the object is black. What's happening?

//basic uv map example from docs

    public Vector2[] UpdateUVMap()
{
Vector2[] uv = new Vector2[this.vertices.Count];

for (int i = 0; i < uv.Length; i++)
{
uv[i] = new Vector2(vertices[i].x, vertices[i].z);
}

return uvs.ToArray();

//uvs.Clear();
}


• Did you remember to set or calculate normals for your mesh? May 21 '20 at 21:27
• The triangles are clockwise so the normals are facing outward. Even if they were random I should still see something since the uv example is straight from the documents...
– kei
May 22 '20 at 1:23
• Did you ask Unity to calculate normals for you based on vertex winding, or did you leave them at their default of (0,0,0)? May 22 '20 at 1:29
• oh pfft, question averted! I was thinking the normal's were implied by the winding direction. didn't realize they were calculated/set separately. i been staring at this screen too long
– kei
May 22 '20 at 8:35

If you don't explicitly provide normals to your newly-made mesh, they'll be left at their default values, and the default value of a Vector3 is (0, 0, 0).
If you want Unity to automatically compute normals for you based on the triangle information, call mesh.RecalculateNormals();