Repeat texture common question

Sooo, really wondering and check tons of pages but couldn’t find what i wanted; is there a way to have

a CUBE, with a texture that repeats when scaling instead of streching.
That only uses one draw call hence i’ve seen many people saying i tweak this


but isn’t good since it create a new material and extra draw call for every cube; I’ve seen you can use a tri-planar shader like here: Radiator Blog: A smoother triplanar shader for Unity. so you can have different material for each side of a cube and only uses one draw call but seem a bit buggy with the position of the texture being off.

So is there a way to fix this problem? basically like what probuilder has by playing around with UVs or shaders, which unfortunately i know nothing of :confused:

Kind of a big question but i’m clearly not the only one with this issues, plz help us :slight_smile:

I just ran a quick test, and supplying uv coordinates in the mesh that are greater than 1.0 will cause the texture to tile. So the following bit of code, when applied to the built-in cube, will cause the texture to be tiled 5x5 on each side:

#pragma strict

function Start() {

var mesh = GetComponent(MeshFilter).mesh;
var uvs = mesh.uv;

	for (var i = 0; i < uvs.Length; i++ ){
		if (uvs*.x > 0.99)* 

_ uvs*.x = 5.0;_
_ if (uvs.y > 0.99)
uvs.y = 5.0;

* mesh.uv = uvs;*
Note that changing the uv coordinates does not break batching.

I had a similar need and could’t find a complete answer anywhere. I ended up writing my own script that changes the UV map according to the desired scale. You simply attach the script to your Cube’s GamObject. Then, anytime you change the scale of your cube you call the reCalcCubeTexture() method. It does the rest.

You should know that because you are customizing the UVs, it creates a mesh instance and the object will no longer use the sharedMesh (it still uses the sharedMaterial). However, I did write in a hack that clears the instance and sets your MeshFilter back to sharedMesh if your cube is ever scaled back to ( 1 , 1 , 1).

It can be found here, and includes a button for your inspector that allows you to change(update) the texture scale in the editor itself. That way you do not have to wait for runtime to see the correct texture.