So, I’ve got this in a custom editor window:
if (actionViewsExpanded[drawingState])
{
SerializedObject serializedObject = new SerializedObject(drawingState);
SerializedProperty onEnter = serializedObject.FindProperty("onEnterAction");
EditorGUILayout.PropertyField(onEnter);
SerializedProperty onUpdate = serializedObject.FindProperty("onUpdateAction");
EditorGUILayout.PropertyField(onUpdate);
SerializedProperty onExit = serializedObject.FindProperty("onExitAction");
EditorGUILayout.PropertyField(onExit);
if (GUI.changed) serializedObject.ApplyModifiedProperties();
}
Superficially, it appears to work. However, the events don’t seem to actually get modified. These are modifying a field on a MonoBehaviour on a prefab, and changing these does not modify the values when I look at the prefab in the Inspector. Also, modifying the inspector only sometimes seems to change what I see in the custom editor.
What it seems like is, the first time I call new SerializedObject(drawingState), it seems to make a copy of drawingState that it uses in perpetuity. When I first open it, it copies whatever values have been set in the inspector. However, from that point on, they’re modifying two completely different objects.
Anyone come across this odd behavior of the SerializedObject class? How do I force it to completely refresh every time? And, why does ApplyModifiedProperties seem to do nothing?