Texture Atlasing

I want to combine a bunch of textures into one material, then use that material for multiple gameobjects so they will batch. However, if I use material offsets to do this, it creates a copy of the material for each object, thus no batching. I noticed that imported meshes use a skinned mesh renderer, which looks like it uses Bounds to achieve the effect I’m looking for. However, I think you can only use that with imported objects.

In other words, instead of having eyes, a nose, and a mouth all on one texture, I want 5 different 2d buildings.

Edit: I thought that SetTextureOffset changed the UVs. Apparently I need to use the method suggested by The comments below. Thanks guys!

You should use the sharedMaterial property in the renderer.
You could even already define it in the material prefab in your project before adding it to an object. In runtime, it will only change one object, but sharedMaterial changes it for everyone.

New answer

Change the uv-coordinates of your vertices instead. It is just a quad, so you can change the vertex data!

You need to offset the UV coordinates of your meshes so they correspond to the atlas coordinates. So there’s 1 atlas containing multiple textures and 1 material applied to multiple objects. What makes this work are the UV coordinates of the mesh. Your material in Unity should have default offsets (1,0 1,0).

You can build an atlas in Unity and create the UV mesh coordinates using an editor script (or tool like Sprite Manager). Or you can manually build an atlas in Photoshop and assign the mapping/UVs in an external 3D program.

ok I have actually done this but not in unity, I usually use one of the following:

1- NVIDIA Texture atlas (you can get it from: Legacy Texture Tools | NVIDIA Developer and it has pretty much all you need)

2- Flatiron from: http://www.texturebaking.com/ this one is a 3dmax plugin and really useful