- Home /
How to update the inspector after editing a prefab via editor-script in 2018.3
So, my inspector doesn't update after I alter the properties on my prefab, but when I call the values via script later it gives my my edited values... unless they are overwritten later by the editor doing a save operation. Marking them dirty doesn't seem to work in 2018.3? Not sure, haven't testing this in other versions. Here's my code though. Oh, and there is somehow a null error on Scene scene = PrefabStageUtility.GetPrefabStage(prefab.gameObject).scene;
returning null for the PrefabStage. And simply marking EditorUtility.SetDirty(prefab);
didn't seem to update the inspector.
[MenuItem("Custom Actions/Prefab Management/Reset GUIDS")]
static void ResetGUIDS()
{
GUIDCount = 0;
List<Item> prefabs = GetAllItemPrefabsInProjectFolder();
List<Item> instances = GetAllItemsInAllScenes();
Debug.Log("Prefabs: " + prefabs.Count);
foreach (Item prefab in prefabs)
{
prefab.overwriteGUIDS = true;
prefab.GUID = GUIDCount;
prefab.overwriteGUIDS = false;
EditorUtility.SetDirty(prefab);
Undo.RecordObject(prefab, "Reset Guid");
GUIDCount++;
Debug.Log("Prefab: " + prefab);
Debug.Log("GameObject: " + prefab.gameObject);
Scene scene = PrefabStageUtility.GetPrefabStage(prefab.gameObject).scene;
Debug.Log("Scene: "+scene);
EditorSceneManager.MarkSceneDirty(PrefabStageUtility.GetPrefabStage(prefab.gameObject).scene);
}
.
.
.
//more code...
.
.
.
}
Hi, I understand that you are modifying the prefab itself (the asset on disk, not from a scene or prefab stage). In this case, simply modify the properties like you do and call PrefabUtility.SavePrefabAsset() (no need of SetDirty() or Undo.RecordObject). Please comment if it works or not as 2018.3 prefab workflow is still a little obscure for me (and I guess other users) :-)
Hey, that worked! Thanks! Inspector is now updating. A quick heads up to everyone though, once you call PrefabUtility.SavePrefabAsset(prefab)
it sets your reference to null, so be aware of that when working with it. @dns Is there some way I can hold onto the reference though? I want to assign the prefab refs to a dictionary after I save them using the GUID as a key.
I did not test it but isn't the reference to the GameObject returned by PrefabUtility.SavePrefabAsset() the reference to the new or updated asset/prefab?
Your answer
![](https://koobas.hobune.stream/wayback/20220612192105im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer
Why is my prefab check failing? 0 Answers
Modify GameObject Components via C# Reflection 2 Answers
Add GUI elements to Scene View? 3 Answers