I have a SerializedProperty which always has the correct value, including after an Undo, but in the Editor it displays the pre-Undo value.
In MyClass I have a public integer ‘width’, and I reference it in MyClassEditor as a SerializedProperty:
private MyClass script;
private SerializedObject serialScript;
private SerializedProperty width;
void OnEnable()
{
script = (MyClass)target;
serialScript = new SerializedObject(targets);
width = serialScript.FindProperty("width");
}
Then in OnInspectorGUI I create the slider in the Inspector
public override void OnInspectorGUI()
{
...
EditorGUILayout.PropertyField(width); //Show slider for width
serialScript.ApplyModifiedProperties();
if ( Event.current.commandName == "UndoRedoPerformed")
{
script.Rebuild();
}
}
Everything seems to work, and in the debugger I can confirm that after an Undo, ‘width’ reverts back to the correct value, but it just isn’t displayed in the Editor, it still displays the pre-Undo value.
How do I force the displayed value to update correctly?
(EDIT: Just noticed, clicking off the editor object in the Hierarchy, and then back on, updates it, so is it some kind of refresh problem?)
Thanks