What's the difference between using GUI.changed, and EditorGUI.Begin/EndChangeCheck?

Hello,

Let’s assume we have this:

GUI.changed = false; 
block1();
if (GUI.changed)
   block2();

and:

EditorGUI.BeginChangeCheck();
block1();
if (EditorGUI.EndChangeCheck())
   block2();

Are their any differences between the two? why would I want to use either? is one more preferable to the other?

Thanks!

1 Answer

1

GUI.changed checks if any value up to that point in the inspector was changed. BeginChangeCheck checks for changes within the next block.

The code you posted is exactly the same in terms of functionality, as far as I can tell.

What BeginChangeCheck does exactly is to push current value of GUI.changed to a stack, then set GUI.changed to false. EndChangeCheck returns GUI.changed AND and set GUI.changed to its current value OR-ed with the previously stacked value. This way you can nest Begin/End change check calls and still detect the changes between pairs of those calls.

–