Texture problem when applying to procedural mesh

I am currently writing a tilemap system in which the map is required to generate at runtime and also have a procedural texture applied. The Mesh generates perfectly and the texture almost fits the mesh but is 1 pixel greater than the set tilesize.

I have messed around with the variables to see if it was just a mesh or texture scaling problem but it appears not.

40392-help.png

Notice that the texture squares are not the same size as the grid AND that they go over the edge of the texture due to appearing to be 1 pixel to large.

When I save the texture onto my hard-drive however, it is 8 * 8. (The image is fuzzy (When uploaded onto this site (it isn’t in Unity)) so I will not upload an example of it).

The most obvious solution I can think of then is scaling the image down to fit the entire board but A. I don’t know how. B. I don’t know how efficient that is. C. It seems like a cheap workaround.
(Right now I am generating an 8 * 8 grid on the X / Y Axis)

void BuildTexture(int size_x, int size_y) //Pass In number of tiles
	{
		int texWidth = size_x * Tile.resolution; //Resolution is currently 1 so the math here is simply 8 * 1
		int texHeight = size_y * Tile.resolution;

		Texture2D texture = new Texture2D (texWidth, texHeight); //Create Texture

		for(int x = 0; x < texWidth; x++) //Loop through texture
		{
			for(int y = 0; y < texHeight; y++)
			{
				Color c = new Color(Random.Range(0f, 1f), Random.Range(0f, 1f), Random.Range(0f, 1f)); //get Random Color
				texture.SetPixel(x, y, c); //I am aware that this is inefficient, this is a standin system to fix the current tiling issues
			}
		}

		texture.wrapMode = TextureWrapMode.Clamp; //I heard this was useful for preventing this problem... It wasn't
		texture.filterMode = FilterMode.Point; //To prevent fuzzy textures

		texture.Apply (); //...

		meshRenderer.sharedMaterial.mainTexture = texture; //Apply Texture
	}

It is also important to note that I do not receive any error messages.

I have somehow managed to fix my code by simply making this change:

int texWidth = size_x * Tile.resolution + 1; //Resolution is currently 1 so the math here is simply 8 * 1
int texHeight = size_y * Tile.resolution + 1;

from:

int texWidth = size_x * Tile.resolution; //Resolution is currently 1 so the math here is simply 8 * 1
int texHeight = size_y * Tile.resolution;

I am unable to see any reason for this but this works… for all resolutions…

Task Accomplished… I guess…