Automatic Material tiling according to object size

So this is the scenario:
Imagine having something like different sized platform for a 2D game.
I have n prefabs which are just cubes.

Each cube has ySize=1 zSize=1 and xSize=n

So for n=3 I have
Cube1 Size (x,y,z) = 1,1,1
Cube2 Size (x,y,z) = 2,1,1
Cube3 Size (x,y,z) = 3,1,1

This is the problem:
My material in order to map correctly the texture, needs to tile differently according to X size of my objects.
So for now I’m creating a different material for every new object I have.

Issues
if I wan to edit the platform material I will have to modify N materials.
if I have 40 different sizes of the same object I have to create 40 different materials.

I’d love to have just ONE object and ONE material, with the X tile changing as I change the X size of my object.
Is that possible?

My first though would be to write a custom shader which map UV based on position of vertices, but maybe there is better approach…

Would love to try, but I really have no idea on how to do that. Yet :slight_smile: