Hi, I have a 3d model with multiple textures and I want to replace one of them inside the editor. The problem is I want to replace the texture in only one model and not in all of the objects that shares the shame material. How can i replace one of the objects materials? If I had only one texture I could just drag a texture and drop it at the bottom and it would work but when I have multiple materials it does not replace the material that i want
Duplicate the material with the texture you want to change, change the texture in the duplicate, replace the material on the model with the duplicate.
myObject.renderer.material.SetTexture(textureId, newTexture);
The above line will set the required texture only on this particular object.
Important note: every time you do this, it will duplicate the material, generating more draw calls. If you have more than one such object, you should save a reference to this material, and later use it for other objects (be setting sharedMaterial):
private Material modifiedMat = null;
private void ModifyTexture(GameObject myObject) {
if (modifiedMat == null) {
modifiedMat = myObject.renderer.material;
modifiedMat.SetTexture(textureId, newTexture);
}
myObject.sharedMaterial = modifiedMat;
}