- Home /
 
Material changes from editor script are lost on save
I am changing a material texture in an editor script. Once run, I can see the changes in the editor window, but when I save my scene or hit play, the changes are lost. Here is my code:
         var mySkyBox = Resources.Load<Material>("mySkyBox");
 
         Undo.RecordObject(mySkyBox, "setting mySkyBox texture");
 
         var texture = new Texture2D(2, 2);
         texture.LoadImage(File.ReadAllBytes("texturePath"));
         mySkyBox.SetTexture("_UpTex", texture);
 
         EditorUtility.SetDirty(mySkyBox);
 
               I have also tried using LoadMainAssetAtPath to load the material but that does not work either.
I am using Unity 5.3.7f1
Can someone please tell me how I can correctly edit a material in an editor script and have the changes persist?
Thanks.
EditorScene$$anonymous$$anager.$$anonymous$$arkAllScenesDirty() also does not work
Your answer
 
             Follow this Question
Related Questions
Query renderer.materials in prefabs in Editor without changing to instance 2 Answers
[solved]Using WWW instead of resources.load causes hang 1 Answer
Does code wrapped in #if UNITY_EDITOR appear anywhere in builds? 3 Answers
When do the Attributes get set? 1 Answer
5.3 Multi scene editor Selection 0 Answers