Hey all,
I am making a copy of a material asset and am trying to load it right after. However, newMat always turns out to be null. Does anyone have any clue why this doesn’t work? I checked in an explorer window and the material does get copied over correctly.
1.
function OnGUI ()
2.
{
3.
masterMatFilePath = "Assets/MasterMaterials/Red.mat";
4.
copyMatFilePath = "Assets/CopyMaterials/Cube-Red.mat";
5.
6.
if(GUILayout.Button("BLA"))
7.
{
8.
if(AssetDatabase.CopyAsset(masterMatFilePath, copyMatFilePath))
9.
{
10.
var newMat = AssetDatabase.LoadAssetAtPath(copyMatFilePath, typeof(Material));
11.
12.
if(newMat != null)
13.
Debug.Log("Asset loaded");
14.
else
15.
Debug.Log("Asset NOT loaded!");
16.
}
17.
}
18.
}