When you need to save changes generated by scripts in the editor
Which one should you use Undo-RecordObject or EditorUtility.SetDirty¶
You should use both because apparently Undo-RecordObject = For objects in scenes EditorUtility.SetDirty = Objects in prefab edit mode,
Majority of the time You don't know which one you're in if you do, If you do know which one it is in its best to do both Still because unity is weird, Better safe than sorry