Diferent materials with diferent textures vs 1 material for diferent gameobjects

I’m wondering what’s the difference between having;

  • 9 gameobjects and 1 material where each gameobject has a different texture but same material

vs

  • 9 gameobjects with 9 materials (one for each of the same type, for example 9 unlit materials) in resource folder with different textures each.

Is there any difference/consideration performance wise?

yes, but it depends of the size of the textures and what platform are you making the game for. the GPUs are quite fast now days and have a lot of memory, 9 game objects will not make much of a difference. so if you give more details of the platform, texture size, texture numbers on a material, stuff like this, you may get more precise answers.

Also you can have a base material and then 9 variants of this base material, but again if you really need this depending of your game.

sorry i think i was unclear, il try to do a better job explaining the 2 scenarios.

first scenario :

I have a resource folder with 1 unlit default material, 1 main texture.

So im going to assign that material to 9 gameobjects, each gameobjects is going to have a different texture in the main texture of the material, i do this from script.

materials[0] = Resources.Load<Material>("mat1");
gameObjectsArray[0].GetComponent<MeshRenderer>().materials = materials;

second scenario :

i have 9 unlit materials (same material type as scenario 1) in the resource folder mat1,mat2,mat3,…mat9, and i have 9 gameobjects, so i can put 1 material on each gameobject respectively, gameobject1 with mat1, gameobject2 with mat2, etc…
Each material is going to have a different texture in the main texture of the material.

Those two scenarios seem very similar to me, btw i assign the materials from script in the second scenario aswell.

Is there a difference performance wise in those two scenarios or some other consideration happening behind the scenes that unity does that could be problematic in any of the two?

You can’t do this though. You would still need 9 different material assets for the 9 different textures.

you right i cant put diferent textures on the same one since it changes all of them.

The difference is: there is no difference. You will need one material for each texture. If at runtime you attempt to access the material of a renderer ( as oposed to the sharedMaterial) so that you can assign different textures to each object then it actually just creates a new material under the hood.

doing this in code changes the equation. i was thinking you were talking about replacing the texture in objects already inside the scene. in the editor.

The end result is the same, as accessing the .material property of a renderer in order to modify it (such as changing a texture) will create an instance of the material and you’ll still have 9 material instances in memory. Just now you have to remember to clean them up afterwards, otherwise they will persist in memory.

And of course accessing the changing the .sharedMaterial will change all instances using said material.