how many uv coordinates should be in a mesh?

so i have generated some basic mashes through code. and though i had the concept but have run into some problems and what ive read is not making sence to me. hopefully someone can correct my understanding.

so far i have set my vertices and then for the triangles i give three indexes to the vertices array.
this works.

i have read that the UV array should be the same length as the vertices array.
but if a UV entry require 4 coordinates… then how is this possible if the verticies array is not a multiple of 4? shouldn’t UV’s be assigned per triangle? anyways please help me understand.

The UV coordinates are part of your vertices. Every vertex has one UV coordinate (technically it can have more but those are for secondary UV channels like lightmapping). You can think of UV coordinates just like normal coordinates but they are in 2d and live in the texture space rather than local / world space. So since every triangle is made up of 3 vertices you will have 3 spatial vertex positions which define where they are located in the world and each vertex has a UV coordinate which defines where this triangle is located in texture / UV space.

I’ve written this UVViewer which is an editor window for the Unity editor to see the UV coordinates visualized in texture space for a specific submesh and a specific UV channel. It might help to better understand the relationship. Other than that you may want to read about UV mapping in general. There are many other sources like this one which give a more user-friendly introduction