Can't change values in serializedproperty array

I am trying to display an array of items inside an editor window using SerializedProperty. The property gets found, and then array is drawn. I can increase the size of the array, but I can’t actually put items in it.

My code, from the OnGUI function of an EditorWindow:

SerializedObject so = new SerializedObject(this);       
SerializedProperty sp = so.FindProperty("weapons");
EditorGUILayout.PropertyField(sp, true);
so.ApplyModifiedProperties();

I’m in Unity 2020.2.2f1. This worked just fine before upgrading. I imagine this is possibly an editor bug, but I’d like to avoid getting my team to upgrade again if I can manage…

I am truly the king of searching for a long time, getting frustrated, making a post, and then immediately finding the answer in a search. I swear I did a search before posting this.

If anyone runs into this issue, the key is to move that SerializedObject declaration out of OnGUI - if you put it in OnEnable, it’ll work. Solution was here:

Thank you - Arrays and lists in the inspector can be reorderable now page-2#post-6881708

4 Likes

Thank you very much for finding this.

1 Like