- Home /
Question by
MastersOfUs · Aug 29, 2019 at 10:46 AM ·
editorprefabeditor-scriptingprefabsserialization
Editing prefab fields from custom editor that are not automatically serialized
Hello, I have a editor script intended to automatically generate icons for some of my Prefabs that will be used as items. The following code is ran when I press a button in the inspector
Item item = target as Item;
string path = AssetDatabase.GetAssetPath(item.gameObject);
GameObject prefab = PrefabUtility.LoadPrefabContents(path);
Item prefabItem = prefab.GetComponent<Item>();
Undo.RecordObject(prefab, "Generated texture.");
PrefabUtility.RecordPrefabInstancePropertyModifications(prefab);
PrefabUtility.RecordPrefabInstancePropertyModifications(prefabItem);
prefabItem.testFloat += 1.5f;
Texture2D icon = ModelSprite.GetTexture(prefab, 128, 128);
prefabItem.Icon = icon;
bool success;
PrefabUtility.SaveAsPrefabAsset(prefab, path, out success);
While the testFloat field saves properly with no issue, I am unable to modify the field of type Texture2D, how could I fix this?
Comment
Your answer
Follow this Question
Related Questions
Mark gameobject field as changed from prefab 2 Answers
Hiding gameobjects in hierarchy make it less expensive ? 0 Answers
Prefab mode doesn't show prefab, still shows old scene. 7 Answers
Automatically update prefab instance 1 Answer
What is runtime analogy for Editor's PrefabUtility.SetPropertyModifications? 0 Answers