I am writing an editor script to update all my material’s texture in a folder under Asset (Asset > Mtl > all .mat files) using texture in another folder (Asset > Texture > all .png)
This is a subset of my code:
Material mtl = new Material(Shader.Find(“Standard”));
// code to store all .mat files in an array
foreach mtl in array
mtl.SetTexture(“_MainTex”, a png texture);
mtl.SetTexture(“_BumpMap”, a png texture);
mtl.SetFloat(“_BumpScale”, bumpScale);
mtl.SetColor(“_Color”, new Color(r, g, b));
EditorUtility.SetDirty(mtl);
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
The changes are reflected in the project window:

But in the inspector and in the scene, only the float changes are saved. The textures are not reflected nor saved:

I also tried the following method:
GameObject cube;
cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
Renderer cubeRenderer = cube.GetComponent();
cubeRenderer.material = mtl;
cubeRenderer.sharedMaterial.SetTexture(“_MainTex”, a png texture);
cubeRenderer.sharedMaterial.SetTexture(“_BumpMap”, a png texture);
cubeRenderer.sharedMaterial.SetFloat(“_BumpScale”, bumpScale);
cubeRenderer.sharedMaterial.SetColor(“_Color”, new Color(r, g, b));
The changes is reflected in project window, inspector and scene



But all disappears when i save the scene.
What should I do to ensure that my changes will be saved permanently?