Search Unity

Can't edit SerializedProperties using EditorGUILayout.PropertyField?

Discussion in 'Editor & General Support' started by Edvard-D, Jul 29, 2017.

  1. Edvard-D

    Edvard-D

    Joined:
    Jun 14, 2012
    Posts:
    129
    I'm working on a custom editor window, which will be used to display multiple ScriptableObjects at a time. Those ScriptableObjects will be displayed using GUILayout.Window calls in OnGUI, which uses the following method to display the window:

    Code (CSharp):
    1. private void DrawNodeWindow(int windowID)
    2. {
    3.     GUI.DragWindow();
    4.  
    5.     var node = CurrentPostprocessor.Nodes[windowID];
    6.     var serializedObject = new SerializedObject(node);
    7.     serializedObject.Update();
    8.  
    9.     var serializedProperty = serializedObject.GetIterator();
    10.     while (serializedProperty.NextVisible(true))
    11.     {
    12.         if (serializedProperty.name != "m_Script")
    13.             EditorGUILayout.PropertyField(serializedProperty);
    14.     }
    15.  
    16.     serializedObject.ApplyModifiedProperties();
    17. }
    Right now I'm testing it with a ScriptableObject derived class that has a single serializable and visible bool. The field is being displayed correctly as a checkbox, except that it doesn't react when clicked on.

    Any thoughts on why this might be?

    EDIT: The problem seems to be the GUI.DragWindow. When I comment it out I'm able to edit the values, but of course no longer able to drag the window. Placing the call after the EditorGUILayout.PropertyField calls (aka, placing it last in the method) makes it work.
     
    Last edited: Jul 30, 2017