# UV's won't set?!

Hi, I’m trying to set the UV’s of a mesh via

``````Mesh m = new Mesh();
m.uv = _uvs.ToArray();
``````

and m.uv always stays empty, no matter what I pass ( tried constant values etc).
What am I missing here ?

Did you set m.vertices first? What is “_uvs”?

–Eric

``````        public Mesh GetMesh()
{
Mesh m = new Mesh();
m.vertices = _vertices.ToArray();
m.triangles = _triangles.ToArray();
m.uv = _uvs.ToArray();
m.RecalculateNormals();
m.RecalculateBounds();
m.Optimize();

return m;
}
``````

The vertices, triangles and uv’s are generated. The mesh works so far, only uv’s are not working. There are exactly as many uv’s as triangles

That’s the problem then…there should be as many UVs as vertices, and you should get an error message if not.

–Eric

I’m not getting an error message. And how should there be as many uv’s as vertices ? Aren’t uv’s bound to triangles ? (1 uv for each triangle)

UV’s should be bound to vertices.

Looking at the documentation (specifically this link) the UV list is generated on the amount of vertices.

In your sample code, how is _uvs initialised and have you checked it is initialised properly?

Gav

Does that mean, I need 2 vertices at the same position if I want the involved triangles to have different textures ?

I tried your code with different sized lists for _vertices and _uvs, and it definitely prints an error message.

No, that couldn’t possibly work…how would you texture a triangle with only 1 UV coordinate? Everything is bound to vertices (normals, uv, tangent, etc.).

–Eric

Nah, I meant 1 uv coord per triangle coord. Thus every point of every triangle has uv coord, and I would use less vertices…