- Home /
Can I change a duplicated objects shader?
I may have a really bad understanding of shaders.
I have duplicated an object, and in the inspector I go tot change the texture and find that it is sharing the shader with the object it was duplicated from. How can I change this shader, or will it be forever linked like this?
Ins$$anonymous$$d of duplicating the prefabs, I just created new ones and added new shaders with different textures.
I'd still be interested in an explanation if anyone has one, and whether duplicating prefabs is generally a bad thing to do?
$$anonymous$$y understanding is that the shaders are a part of the material and because you duplicated the prefab they were referencing the same material. When you created a new one you may have made a new material. i may be wrong here but if you where to have lets say material1 set up to use texture1 and material2 set up to use testure2 you would be able to swap what texture your prefab is using in the materials option of the meshrender component.
Answer by iwaldrop · Apr 15, 2013 at 06:17 PM
You can always set the shader at runtime:
void ChangeShader(Shader s)
{
renderer.material.shader = s;
}
This is always better than junking up your prefabs and materials folder with specific instances for just a shader or texture change.