EditorWindow GameObject Array

I’ve been trying to find a source on how to put a gameobject array (or list) in a custom editor window that will accept multiple items dragged into it at once. Is there a simple way to do this with an ObjectField? I tried using a foreach loop, but it gives me an error.

So I finally was able to piece everything together, and for anyone else who might have the same problem:

public class MyClass : EditorWindow{

    public GameObject[] someThings;

    [MenuItem("Window/My Class")]
    public static void ShowWindow(){

        EditorWindow.GetWindow <MyClass>("My Class");
    }

    void OnGUI(){
      
        ScriptableObject scriptableObj = this;
        SerializedObject serialObj = new SerializedObject (scriptableObj);
        SerializedProperty serialProp = serialObj.FindProperty ("someThings");

        EditorGUILayout.PropertyField (serialProp, true);
        serialObj.ApplyModifiedProperties ();
    }
}

I had seen very similar code segments around, but I didn’t think they fit my use case.

What took me a while to realize was that EditorWindow derives from ScriptableObject, so I can keep everything I need in this class by referencing itself. A SerializedObject can be initialized from that, and a global variable in the class can be accessed as a SerializedProperty.

18 Likes

Thanks!
exactly what I needed

this is better than create a reorederablelist i’ve find before;)