Issues with UV in generated mesh

I’m having some issues assigning UV values to my script generated mesh. It’s likely because I don’t completely understand UV mapping, so if anyone also could point me to a good informational guide for mesh UVs that would be helpful (internet searching has caused some confusing results).

I’m generating a mesh like this:

The mesh is arbitrarily long. I want the mesh renderer material to repeat for every individual square, E.g vertexes [1,2,3,4] have the whole texture, [5,6,7,8] full texture, repeat…

Setting each group’s UVs like this doesn’t render correctly:

            // where i is the bottom left
            uv[i] = new Vector2(0, 0);
            uv[i + 1] = new Vector2(1, 0);
            uv[i + 2] = new Vector2(0, 1);
            uv[i + 3] = new Vector2(1, 1);

Can someone help fill in the gaps as to the proper usage?

Can you show us how you generate the mesh vertecies and triangles and what the result looks like?
Also why not using 1,2,3,4 - 3,4,5,6
instead of 1,2,3,4 - 5,6,7,8 So I mean you can simply merge verticies, the UV will simply repeat, you only have to assign values greater 1 for the uv, e.g. point 5 (in your case 7) would be new Vector2(0, 2);
Triangle definition will then be 3,5,4 instead of 5,7,6 for exmple.

UVs are the coordinates in normalised texture space. Your description of what you are doing seems fine, I don’t think it’s a lack of understanding. As McDev02 points out, you can exceed the bounds of the texture, and as the default behaviour is to “wrap” around in texture space and this can help you reuse vertices (so what you have as vertices 5 & 6 need not exist and the vertices that follow for the end points of the 2nd quad can have uv coords (0.0, 2.0) and (1.0, 2.0))

Yes, I know I can reuse the vertices but the code becomes very confusing at that point. The extra vertices make it much more readable since I can treat each square as completely independent.
I guess my confusion stems from this point:

Why does the second quad have (0.0, 2.0) and (1.0, 2.0), could it not simply have (0, 1) and (0, 1) like the first? I assume that would be the case because ‘normalized’ implies the values should always be between 0 and 1

You don’t have to do that, that was simply me trying to elaborate on what MacDev02 said about reusing vertices…each quad / triangle pair can have exactly the same UV coords like you want and that’s fine too.

I think your issue is elsewhere. Like are you sure your UVs match up with your positions, and that your indicies are alright if you are using an indexed mesh?

I think they are correct but I can check again. I’m working with for loops mostly so perhaps that is causing me trouble but it’s only the UV maps that seem incorrect. I’m getting mostly a solid color on all the meshes except for one, which got the texture but it’s not right.