- Home /
Create new mesh from script always black color even i change material.
Hi everyone who read this post.
I am using 2019.3.0b1 with URP.
I have problem that my mesh which i created from script always show black color even i change material.
this is my script very simple to create single triangle
public class DrawMeshManager : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
DrawMesh();
}
private void DrawMesh()
{
Mesh mesh = new Mesh();
Vector3[] vertices = new Vector3[3];
Vector2[] uv = new Vector2[3];
int[] triangles = new int[3];
vertices[0] = new Vector3(0, 0);
vertices[1] = new Vector3(0, 100);
vertices[2] = new Vector3(100,100);
uv[0] = new Vector2(0,0);
uv[1] = new Vector2(0,1);
uv[2] = new Vector2(1,1);
triangles[0] = 0;
triangles[1] = 1;
triangles[2] = 2;
mesh.vertices = vertices;
mesh.uv = uv;
mesh.triangles = triangles;
GetComponent<MeshFilter>().mesh = mesh;
}
// Update is called once per frame
void Update()
{
}
}
This is what i look after create mesh from script. As you can see that my mesh is completely black
And this is information of my materials.
Please help me my problem. Thank you.
Experiencing the same problem. I've done runtime mesh gen in Unity for years and this is the first time I've run into the problem. I tried setting vertex colors to white in case for whatever reason URP was defaulting them to black, but no luck.
Answer by mansoor090 · Oct 23, 2019 at 07:58 AM
I had this problem once.
Try this command : mesh.RecalculateNormals(); if your problem isnt solved. try commenting out // mesh.uv = uv;