Do I need to use SetDirty in my editors if I'm using SerializedProperties?

I’ve been making tons of custom editors. At first I started using target only as SPs was a pain to work with - but then I realized the benefits SPs give, and managed to get along.

But at no point of time, I used SetDirty - I still see it in some editor scripts, but don’t really know why they ever need it.

The docs says that you need to SetDirty on a prefab for ex, if you change a value in one of its MonoBehavoiurs for it to be saved to disk.

I haven’t found any need to do that. I could change a value in a prefab’s MB, enter/exit play mode, exit/re-enter Unity - the value is still there.

So what’s the use of SetDirty, and when do I ever need it? Is this some legacy thing that was used when dealing with target directly?

Thanks!

SetDirty is needed if you change values without using SerializedProperty. Pretty much anywhere you’d need to add a manual call to Undo.Record, you’d want to call SetDirty.

As an example, I have some ScriptableObject subclasses with accessor properties that modify private, serialzied members. I have to use SetDirty inside these accessors.