Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Editor.serializedObject not working

Discussion in 'Immediate Mode GUI (IMGUI)' started by MaT227, Aug 14, 2015.

  1. MaT227

    MaT227

    Joined:
    Jul 3, 2012
    Posts:
    628
    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.

    Code (CSharp):
    1. private SerializedProperty  _propertyA;
    2. private SerializedProperty  _propertyB;
    3. private SerializedProperty  _propertyC;
    4.  
    5. public void OnEnable()
    6. {
    7.      _propertyA = serializedObject.FindProperty("_A");
    8.      _propertyB = serializedObject.FindProperty("_B");
    9.      _propertyC = serializedObject.FindProperty("_C");
    10. }
    11. public override void OnInspectorGUI()
    12. {
    13.      serializedObject.Update();
    14.  
    15.      EditorGUILayout.PropertyField(_propertyA, new GUIContent("A"));
    16.      EditorGUILayout.PropertyField(_propertyB, new GUIContent("B"));
    17.      EditorGUILayout.PropertyField(_propertyC, new GUIContent("C"));
    18.  
    19.      serializedObject.ApplyModifiedProperties();
    20. }
    Anybody knows why ?
    Thanks a lot !
     
    Last edited: Aug 14, 2015
  2. MaT227

    MaT227

    Joined:
    Jul 3, 2012
    Posts:
    628
    Edit: Added Code.
     
  3. Hoonius

    Hoonius

    Joined:
    Jul 18, 2013
    Posts:
    8
    Are those variables public? I had similar situation and it was that easy fix.
     
  4. MaT227

    MaT227

    Joined:
    Jul 3, 2012
    Posts:
    628
    @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.
    Code (CSharp):
    1. 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.
     
    Last edited: Aug 14, 2015
    Hoonius likes this.