Mesh.uv is out of bounds.

Unity throws the following exception:
Mesh.uv is out of bounds. The supplied array needs to be the same size as the Mesh.vertices array.
when I run this line:

mesh.uv = Unwrapping.GeneratePerTriangleUV(mesh);

This kind of error happens when you try to assign an array of uv which is longer (or shorter?) than the vertices array. This can’t happen since there’s one pair of uv per vertex (and per uv set). uv and vertices arrays must have the very same length.

It seems this unwrapping method generate 3 uv pairs for each triangle. But if you have triangles with common vertices, the number of uv generated will exceed the number of vertices ==> error.

It’s an editor class:

Can’t I have per triangle uvs? Multiple triangles can include the same vertex. The reason I want to achieve this is that I have a sphere that I want to map. Now if I wrap the texture around the sphere there’s going to be vertices that need to have the uv coordinate of both 0 and 1.

the documentation says that you’ll have to merge yourself the uvs of triangles with merged vertices.

thanks I think I missed that part, I solved the problem though by mirroring-tiling.

Hi,
I try to figure out how should I merge the uv’s too.
I understand that if there are shared vertices, the number of uvs that are produced is bigger than the number of the vertices. I do not understand how to use mirroring - tilling to do this. Or perhaps hencz uses this approach to wrap the texture around the sphere, not to merge the uv’s.
I would appreciate any suggestions, thanks.
-Ippokratis

Well, in my case, the mesh was a sphere generated procedurally, so I used mirroring to texture the mesh - tile the texture on every quad.

Yup, nice you got it sorted this way.
I wonder how to solve the merging problem though (edited the post above).

As far as I know there’s no way to have more than one uv per vertex, the only way would be to duplicate the vertices.
Here’s an illustration on how I solved it (top - duplicated vertices, bottom - mirroring):

1 Like

Hi,
Thanks for the answer.

Yes, this or eliminate certain Vector2 items from the uv array that correspond to the shared vertices.
Again, thanks for the illustration, truth is that I do not quite understand it but thanks anyway.

the numbers are uv coordinates, the red arrow is the texture

Read the entire thread but having issue when reading FBX file.

I have more uvs than vertices then difficult to match both.

Well, the export method I know is to have the same number of vertices and uvs when writing the file, doing this way when exporting my stuff under openGL for some test.

But currently trying to understand the “how to” of the FBX file.

I success to draw an entire model, the stripping method seems to works, I do not have reversed tri.
When it comes of the Uvs, that is completly broken.

I do not really success to find a way on how to make it match properly.

Does someone has experience with FBX format and could say a little more? :frowning:

Hi, am creating a procedural mesh terrain. Tile is having three different textures. I want to apply different textures on different uvs (UV,UV1,UV2) . if i apply in an order means it gives me road kind of thing. Other places are green grass kind of thing. while am trying to apply using surface shader .Other than given UVs last pixel clamped(dont know the exact name) on next UVs. So the final ThreeImagesApplied.png looks like a blending of given images.

Thanks in advance :slight_smile: - am using [ Unity 5.3 ]