- Home /
How can I change default shader for new/imported objects?
I am trying to figure out a way to change the default shader for imported objects. But I cannot seem to find any information on this process. First of all, is there some sort of editor script for this and is it possible?
I have looked at the Change Mass Materials script found here.
http://answers.unity3d.com/questions/14454/is-there-a-way-to-change-the-shader-on-all-meshes.html
But the first one only changes the material, not the shader. And the other one fails to even work.
I am guessing I need to make an editor script to recognize when a new object is imported and then change the default shader to one of my choice. Just not sure where to start. Any help on this issue would appreciated! Thank you!
UPDATE:: I ended up writing a script that changed the shader when a script is applied to an object. This isn't exactly what I wanted as it's an extra step. I would rather have the ability to pick the shader that will be used for the imported objected, rather than having it chosen for me by Unity.
Here is the script.
Shader newShader = Shader.Find("Unlit/Texture");
if (newShader == null)
Debug.Log("Shader is null!");
else
renderer.sharedMaterial.shader = newShader;
Answer by Owen-Reynolds · Jan 25, 2013 at 03:26 AM
The shader is part of the material, so the material mass changer should work.
In more detail, suppose you want everything to use Specular. Even if you could just change your current material to use the spec shader, you'd also want to set the spec color and shininess, which are material properties. So, simplest way is to just make a whole new material with the spec shader and those settings.
But if I change the material I lose all the settings of the previous material. Like let's say I imported a fbx model and it came with a texture and it looked fine and dandy, but I wanted to change JUST the shader without affecting the material. How would I go about that, besides manually doing it? Because If i change the material my texture is lost.