Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

How to reuse the same Material but with different Texture?

Discussion in 'Shaders' started by Asim Arif, Jul 5, 2014.

  1. Asim Arif

    Asim Arif

    Joined:
    Nov 6, 2012
    Posts:
    22
    Hi,
    I don't know whatever I'm doing in my game is the best way or not? So, that's why, I'm writing here so you guys can help me out to follow the best way. Here is my scenario:

    I have different game objects which appear and disappear with the passage of time based on the user interaction. All of these game objects are using different materials which are created by me but, under the hood, all those materials are using the same Shader which is "Unlit/Transparent". The only difference in each defined material is the Texture. So, now, I have around 26 game objects which means I end up with 26 different materials all using the same "Unlit/Transparent" shader but each material is using different Texture.

    I was reading Unity documentation and as per their documentation, we should minimize the materials as much as possible. So, is there any way, I can define only one material using "Unlit/Transparent" shader and reuse that material for all of the game objects and providing them different Textuer either through Unity Editor or through Script?

    I just want to implement the best practice.

    Thank you very much.
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,398
    Yeah, that's kind of an important difference. ;) There's no way to have the same material with two different textures...that's an inherent contradiction. A common technique is to use a texture atlas, and change the UVs of the models to show different parts of the atlas. Of course in that case it means having many different instances of the model using the same material, but that's typically cheaper than having many different materials.

    --Eric
     
    Flailer likes this.