- Home /
BeginChangeCheck & EndChangeCheck not working?
I can't seem to get EditorGUI.BeginChangeCheck() and EditorGUI.EndChangeCheck() to properly save changes made to a EditorGUILayout.Popup(). Here's my block of code, running inside OnInspectorGUI() of a Custom Editor.
EditorGUI.BeginChangeCheck();
useTextBank.selectedBank = EditorGUILayout.Popup(useTextBank.selectedBank, useTextBank.textBank.bankSets [0].textItems.ToArray());
if (EditorGUI.EndChangeCheck()) {
useTextBank.RefreshText();
Undo.RecordObject(useTextBank, "Select TextBank");
}
I'm trying to match the usage defined here: https://docs.unity3d.com/ScriptReference/EditorGUI.BeginChangeCheck.html but the modified object doesn't not save with scene/prefab after modifying it's popup in the inspector, nor does an Undo entry get created. I'm using Unity 5.6.4.
I know I can manually track if the value was changed with a temp variable, but I was under the impression BeginChangeCheck() was supposed to take care of that.
Is it possible to record selectedBank ins$$anonymous$$d of useTextBank?
Edit Also, ins$$anonymous$$d of Record Object, you could try using Register Complete Object Undo or even Register Full Object Hierarchy Undo.
Answer by Adam-Mechtley · Jan 15, 2018 at 08:05 PM
I don't have all the context here, but from the looks of it I think the problem is that you are not using Undo.RecordObject
at the right time. Per the documentation, you should call it before you make changes, and it looks here like you are calling it after.
Thanks - that was the problem! Still have to use a temp variable (as in that example) but I suppose that's just how it has to work.
Your answer
Follow this Question
Related Questions
How to properly handle Undo events in custom inspector? 0 Answers
CustomPropertyDrawer with UnityEvent 1 Answer
Using a CustomEditor in the inspector and also seeing normal inspector fields 1 Answer
How to show type text in EditorGUI.ObjectField? 1 Answer
Why is play mode reverting my scriptableobject to a previous serialized state? 2 Answers