I generated a material and set to a GameObject in Editor code and set a texture to it, all looks fine when the code finish. But as soon as I save project or run the scene, the material lose its texture. The code looks like this:
Material material = new Material(Shader.Find("Unlit/Texture"));
AssetDatabase.CreateAsset(material, asset_path.Replace(".asset", ".mat"));
material.mainTexture = new_texture;
AssetDatabase.ImportAsset(asset_path.Replace(".asset", ".mat"), ImportAssetOptions.ForceUpdate);
I can manually set the texture again, but I can’t understand why the material lost its texture in the first place, anyone knows about this?