dbrizov / NaughtyAttributes

Attribute Extensions for Unity
MIT License
4.52k stars 465 forks source link

[Issue] When using a [Button] that changes a variable it doesn't generate undo/redo commands #301

Open dbrizov opened 2 years ago

rhys-vdw commented 2 years ago

This doesn't seem like a bug to me, you need to do:

[Button]
void Change() {
  _foo = Random.Range(0, 20);
#if UNITY_EDITOR
  UnityEditor.EditorUtility.SetDirty(this);
#endif
}

This applies to any time you change a field outside of play mode, including MenuItem etc.

dbrizov commented 2 years ago

I also don't think it's a bug. A guy reported it via email, and I wanted to investigate just in case. I was having some issues with prefabs in a prefab instance, and want to see if something regressed

dbrizov commented 2 years ago

The changes aren't lost btw, I am setting the object dirty in the editor, and the prefab serializes to disk. What the guys meant is that the changes don't generate undo/redo commands.