Search Unity

  1. Get the latest news, tutorials and offers directly to your inbox with our newsletters. Sign up now.
    Dismiss Notice

Mesh.uv is out of bounds.

Discussion in 'Scripting' started by hencz, May 29, 2011.

  1. hencz

    hencz

    Joined:
    Aug 19, 2010
    Posts:
    86
    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:
    Code (csharp):
    1.  
    2. mesh.uv = Unwrapping.GeneratePerTriangleUV(mesh);
    3.  
     
  2. Krobill

    Krobill

    Joined:
    Nov 10, 2008
    Posts:
    282
    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.
     
    Last edited: May 29, 2011
  3. hencz

    hencz

    Joined:
    Aug 19, 2010
    Posts:
    86
  4. Krobill

    Krobill

    Joined:
    Nov 10, 2008
    Posts:
    282
    the documentation says that you'll have to merge yourself the uvs of triangles with merged vertices.
     
  5. hencz

    hencz

    Joined:
    Aug 19, 2010
    Posts:
    86
    thanks I think I missed that part, I solved the problem though by mirroring-tiling.
     
  6. Ippokratis

    Ippokratis

    Joined:
    Oct 13, 2008
    Posts:
    1,520
    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
     
    Last edited: Oct 31, 2011
  7. hencz

    hencz

    Joined:
    Aug 19, 2010
    Posts:
    86
    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.
     
  8. Ippokratis

    Ippokratis

    Joined:
    Oct 13, 2008
    Posts:
    1,520
    Yup, nice you got it sorted this way.
    I wonder how to solve the merging problem though (edited the post above).
     
  9. hencz

    hencz

    Joined:
    Aug 19, 2010
    Posts:
    86
    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):
     
  10. Ippokratis

    Ippokratis

    Joined:
    Oct 13, 2008
    Posts:
    1,520
    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.
     
  11. hencz

    hencz

    Joined:
    Aug 19, 2010
    Posts:
    86
    the numbers are uv coordinates, the red arrow is the texture
     
  12. sama-van

    sama-van

    Joined:
    Jun 2, 2009
    Posts:
    1,654
    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? :(
     
  13. RajeshTamizha

    RajeshTamizha

    Joined:
    Dec 16, 2020
    Posts:
    1
    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 :) - am using [ Unity 5.3 ]
     

    Attached Files:

unityunity