Quantcast
Channel: Latest Questions by sebj
Viewing all articles
Browse latest Browse all 12

Modify prefabs in editor script

$
0
0
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();

Viewing all articles
Browse latest Browse all 12

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>