Changing the materials in Editor Mode Without Getting the leak Error

is there is any way to change the materials by code at editor time without countering this error

Instantiating material due to calling renderer.material during edit
mode. This will leak materials into
the scene. You most likely want to use
renderer.sharedMaterial instead

in most cases i generate temp material this way

Material m = new Material(Shader.Find(SHADER_NAME));

or 

renderer.material = new Material(Shader.Find(SHADER_NAME));

going to answer my own question , so it might help if any one else has the same issue

just use the sharedMaterial instead

and for case of array of materials for single object define a new array of materials make
changes to it then assign it as objects shared materals

 Material[] faceMaterials = new
> Material[4];
>             faceMaterials[0] = matSetup( Color.white, faceTexture,
> facialTexture);
> 
>             faceMaterials[0].name = "Face";    
>             faceMaterials[1] = matSetup(Color.white ,eyeTexture);
> 
>             faceMaterials[1].name = "Eyes";
> 
>             faceMaterials[2] = matSetup(Color.white ,null);    
>             faceMaterials[2].name = "Teeth";    
>             faceMaterials[3] = matSetup(new Color(0.933f , 0.731f ,
> 0.731f , 1) ,null);    
>             faceMaterials[3].name = "Toungh";    
>             Facetransform.renderer.sharedMaterials = faceMaterials;


-----------------------

    Material matSetup(Color col , Texture tex)
    {
       Material mat = new Material(Shader.Find("Diffuse"));
       mat.SetColor("_Color",col);
       mat.SetTexture("_MainTex",Resources.Load(tex) as  Texture);
       return mat;
    }

Thank you for posting your solution! I was having a similar problem. Assigning a new array to sharedMaterials instead of altering the existing one solved my problem :slight_smile:

I was looking for something more like: Material Leak in Editor - Unity Answers