- Home /
Question by
gabriele_unity931 · Sep 19, 2019 at 09:57 PM ·
materialassetbundlefile
How do I save a material from an asset bundle to file locally ?
My goal is to save to file the material contained within the AssetBundle in Editor Mode. Given the function below I keep getting the error:
"Couldn'd add object to asset file because the Material 'my_material' is already an asset at '' !"
It's kind of confusing because the Material m that is coming from the LoadAsset method is nowhere to bw found in the "Assets" folder and the "Assets/materials" one is empty.
public static Material SaveMaterialToFile(bute[] assetData, string materialName) {
AssetBundle b;
Material m;
AssetBundle.UnloadAllAssetBundles(true);
b = AssetBundle.LoadFromMemory(assetData);
m = bundle.LoadAsset<Material>(materialName + ".mat");
b.Unload(false);
AssetDatabase.CreateAsset(m, "Assets/materials/" + maeterialName + ".mat");
return m;
}
At this point I am not sure how to proceed. I tried multiple things and although it seems straightforward, I can't get it to work. Any suggestion ?
Comment