I am trying to write a script that will update the material settings on a set of prefabs, which I can then save.
I have seen a number of questions asking to do this, but none of the examples work. My code is below.
Whenever I run this, the editor reacts by re-importing assets, and there are no exceptions indicating that my call to ReplacePrefab() is incorrect - but the prefabs themselves remains unchanged.
What have I missed?
AssetDatabase.StartAssetEditing();
var guids = AssetDatabase.FindAssets(" t:GameObject",new string[]{"Assets/city_assets"});
foreach(var g in guids)
{
string path = AssetDatabase.GUIDToAssetPath(g);
GameObject prefab = AssetDatabase.LoadAssetAtPath(path, typeof(GameObject)) as GameObject;
GameObject instance = Object.Instantiate(prefab);
UpdateMaterials(instance); //operates on the components of instance
PrefabUtility.ReplacePrefab(instance, prefab, ReplacePrefabOptions.ConnectToPrefab);
}
AssetDatabase.StopAssetEditing();
↧