- Home /
Setting a material texture and saving it
So I am creating materials in code and trying to save them but for some reason when I save a material the texture ALWAYS reverts to "none"
How can I save the material WITH it's texture or even possibly set it after I save the new mat ?
Here is my code
Material newMaterial = new Material(Shader.Find("Diffuse"));
string matPath = "Assets/Resources/Atlas/" + textureName + "/" + textureName + ".mat";
AssetDatabase.CreateAsset(newMaterial, matPath);
newMaterial = (Material)AssetDatabase.LoadAssetAtPath(matPath, typeof(Material));
newMaterial.SetTexture(textureName, texture);
AssetDatabase.SaveAssets();
#endregion
The bit where I set the texture seems to do nothing as my newly saved material has no texture set ?
Comment
Best Answer
Answer by DannyLZS · Jun 24, 2013 at 04:08 PM
Turns out I had to call ...
AssetDatabase.SaveAssets();
and
AssetDatabase.Refresh();
before I could attempt to load it back in