Editor.serializedObject not working

Everything is in the title.
The Editor.serializedObject property is not working when following the example provided in the Editor documentation.
The changes in the inspector fields are not applied.

private SerializedProperty  _propertyA;
private SerializedProperty  _propertyB;
private SerializedProperty  _propertyC;

public void OnEnable()
{
     _propertyA = serializedObject.FindProperty("_A");
     _propertyB = serializedObject.FindProperty("_B");
     _propertyC = serializedObject.FindProperty("_C");
}
public override void OnInspectorGUI()
{
     serializedObject.Update();

     EditorGUILayout.PropertyField(_propertyA, new GUIContent("A"));
     EditorGUILayout.PropertyField(_propertyB, new GUIContent("B"));
     EditorGUILayout.PropertyField(_propertyC, new GUIContent("C"));

     serializedObject.ApplyModifiedProperties();
}

Anybody knows why ?
Thanks a lot !

Edit: Added Code.

Are those variables public? I had similar situation and it was that easy fix.

@Hoonius , yes they are public. The only workaround if to create a new serializedObject and use it instead of the base one. But I don’t think it’s the good solution.

newSerializedObject = newSerializedObject(target);

Edit: I found the issue. For debugging purpose, I used Editor.DrawDefaultInspector but now I removed it and it’s working well.

1 Like