How do I get a material to tile dynamically?

Hi all,
I’ve got a question regarding materials that I haven’t been able to figure out. I’m working on building an isometric dungeon system with procedural rooms that are then connected with hallways.

My current plan is to create a hallway prefab that is smart enough to stretch between rooms. Unfortunately, I’ve run into a problem with materials assigned to the hall. When I stretch a hall, the textures stretch as well. If I shrink a hall, the texture shrinks as well. This makes sense obviously since the uvs on the hall (which are a series of planes) assume 0-1 on the lengths.

I want the material to tile the texture associated with it. Unfortunately, the only way I’ve seen to do this is to change the tiling on the material itself. The problem with this is that if there are 2 different sized walls with the same prefab, the shared prefab means that one material overrides the other.

I’ve seen this done in games, so I’m curious if anyone has a suggestion on how to do this. I’ve attached an image that sort of shows the problem I’m having.

Thanks!

It’s not possible to do that with a single material. You will need different material instances for each hallway that needs different tiling. Just touching Renderer.material causes Unity to create a new instance for that object anyway, so it’s easy enough to do.