change shader of multiple materials automatically

Hey all,

After importing a big scene in unity I need to change all the shaders in the materials from "Diffuse" to "Self-Illumin/Diffuse". I was looking for a way to do this automatically because by hand would kill me :) Can't be such a big thing, I thought first, but neither I found a solution nor I could program it for myself.

Maybe someone here had the same problem and can help with a solution. Also a modification of the MassMaterialEditor Script would be perfect.

I was googling for a solution and this was one of the relevant top hits... Anyway, I was forced to grind my own solution... and this might give some people an idea on how to do it.

I use this code to turn the material of a gameobject to 'Transparent/Diffuse'. You also have to drag an empty 'Transparent/Diffuse' material from the assets to 'transparentMaterial' in the inspector. You dont have to do it at 'Start()', i just made that to make the code shorter...


public class SomeClass : MonoBehaviour {
public GameObject instantiatedTarget;
public Material transparentMaterial;
    void Start () {
    void ReplaceMaterialRecursively(GameObject g) {
        Material oldMaterial;
            oldMaterial = g.renderer.material;
            g.renderer.material = transparentMaterial;
            g.renderer.material.color = transparentMaterial.color;

        foreach(Transform t in g.GetComponentInChildren<Transform>())

Am currently seeking the solution to this myself. The only way I know of changing a shader on a material through code is through Material.shader so use that in conjunction with the [ExecuteInEditMode] tag? But the material will need to have been placed on an object for that to work, so you'll still have to drag all materials into the scene by hand. Maybe make a script that loads every material in your scene onto a dummy object so then you can edit them in batch.

I have a slightly different take, that does all the materials with a given shader in the scene, here: