I have a bunch of cubes that I am texturing and I need to change the textures during gameplay but I’m not sure the best way to go about it.
I think these are my options.
Create a bunch of different models in blender and set the UVs manually to every texture combination I need.
Create one cube model and add a bunch of different materials to it in blender and then in unity I can create a material for each tile and then set multiple materials to the cubes for each face.
I think both options are not ideal for performance because I would have a large amount of models/materials being used.
Another option would be to make a big texture atlas and then change the UVs of the cube through code but from my research that looks extremely tedious and I dont think it looks possible to change the UVs of specific faces?
What is the common procedure for this? Or is there a better way I dont know of? Thanks!
You can change shader properties on materials at runtime. Something along the lines of meshRenderer.material.SetTexture("_MainTex", myNewTexture) would work.
Keep in mind the downsides of changing material properties at runtime, like the fact that it creates a new instance.
So in blender I would create my mesh for a material to be used on each face and then in unity I just create one material and used the same material 6-8 times for the cube for each face and then when I need to change something I can change the texture through the shader.
I think this sounds good. Having one material being used multiple times on each mesh is probably faster. Thank you very much.
Basically, the material has a texture property. At runtime, you can change the texture on that instance of that material if you need to, or you can change the property for ALL instances of the material (called the “shared material”).
Another way would be to just create all the materials manually in your project folder, with each one using a different texture. Then you can assign each one to each cube. Then instead of changing textures on the material at runtime (which would create material instances and thus more garbage for the GC to handle), you could just swap what material the mesh renderer is using.
Oh ok, I thought creating a bunch of different materials to be used like that would be bad for performance but I’ll do that if you think it would be faster. Thanks again.