Question by
David_CGA · Feb 25, 2021 at 05:28 PM ·
c#editor-scriptingarrayseditorwindow
Modify Array in Editor Window - 2020+
I am trying to make an array that I can modify by changing the elements in the array as well as adding and removing elements from the array.
So far from previous examples the code I have half works, I am able to add and remove elements to a array but I am unable to change the value of any element.
Here is my example code that is not fully working
public class windowTest : EditorWindow
{
public GameObject[] gameObjects;
[MenuItem("Tools/Test Window")]
public static void DisplayWindow()
{
windowTest window = EditorWindow.GetWindow<windowTest>();
window.Show();
}
private void OnGUI()
{
ScriptableObject target = this;
SerializedObject so = new SerializedObject(target);
SerializedProperty objectsProp = so.FindProperty("gameObjects");
EditorGUILayout.PropertyField(objectsProp, true);
so.ApplyModifiedProperties();
}
}
I am able to add and remove elements to the array in the window without the ApplyModifiedProperties() function and the function is returning false but I am not sure what I need to do to make the properties apply successfully
Replies are greatly appreciated
Comment