I breaking prefab instances pretty often. So i want to have a shortcut for it and wrote a simple script. It works fine, but undo does not work, even with Undo.RecordUndo(obj, “history name”). How can i improve this script, to make undo work?
Here is the script:
[MenuItem("MyGameTools/Unconnect prefab (break) %u")]
static void UnconnectPrefab() {
string msg = "";
if (Selection.gameObjects.Any()) {
foreach (var go in Selection.gameObjects) {
Undo.RecordObject(go, "disconnect prefab " + go);
PrefabUtility.DisconnectPrefabInstance(go);
EditorUtility.SetDirty(go);
msg += go.name + " – disconnect prefab\n";
}
} else {
msg = "No objects seleted to disconnect prefab";
}
Debug.Log(msg);
}
Alternativly any method to map editor’s “Break Prefab Instance” to hotkey would work for me too, because undo works there out of the box.