Optimize grid texture placing

Hello again!

I am creating a sims like building game. Everything works perfect, but I think the game needs to be a bit faster. (optimization)
I have a prefab of a plane. The plane uses the standard shader with a grass texture.
At the start of the game a grid of 50x50 is created of this prefab. I can place things on those planes and build walls on them.
I can also build paths, or floors. When placing a floor my code simply changes the material.maintexture of the renderer component of that specific plane. This works fine.
But when optimizing, I want to reduce batches. So how would I make one mesh where I can change the texture at a specific point?
Or how could I optimize the things I am doing right now? (Talking about placing floors)

Thank you for your time, I can provide more information if needed.

A modest bump

Hello all,

I still dont have a single clue where to start with optimization in this case. I understand I could make the grid one mesh, and when placing floor textures on the mesh I could redo some uv mapping. I just do not think the remapping is very fast. Although it would give me a decrease in draw calls and batches.

If anyone has some ideas, please tell me :).

If it is not clear what I mean by placing floors, I will make a gif showing what I mean.

Thank you in advance,
Floris Weers

Since unity batches meshes with same texture and uniform scale(1,1,1). You can use an atlas texture(grid of all your textures on one big texture). Then either make a separate tile(mesh) for each piece of the texture and swap tiles with code. Or use material.SetTextureOffset to offset UVs to each piece of the texture.

1 Like