NaughtyAttributes icon indicating copy to clipboard operation
NaughtyAttributes copied to clipboard

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

Open dbrizov opened this issue 3 years ago • 3 comments

dbrizov avatar Feb 14 '22 18:02 dbrizov

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.

rhys-vdw avatar Feb 15 '22 00:02 rhys-vdw

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 avatar Feb 15 '22 06:02 dbrizov

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.

dbrizov avatar Feb 15 '22 06:02 dbrizov