Array of objectFiled in editorWindow

Hi I need to iterate through array of objectField to display them in editorWindow.

But, they are all null(duh), after initializing the array, so unity spills error of the null object reference variety.

Is there a way to iterate through the array and display them in the editor window without any fancy hacks?
Or maybe change them from null to empty? Is that even a thing?

static Object[] source;

public static void Init(){
  ...
  source = new Object[6];
  ...
}
          
public void OnGUI(){
  for(int i = 0 ; i<6 ; i++){
  // this gives errors:
  source _= EditorGUI.ObjectField(new Rect(10,50*i,75,16),source*,typeof(GameObject));*_

}
}
I’m just soo tired of all those unity driven hacks to everything unity based that my brain refuses to work anymore, even on such trivial things like this one. Please help.

well, i don’t know how to do that. But, you can try doing this

public List<Object> yourList = new List<Object>(); //list of Objects
public List<string> yourList = new List<string>(); //list of Strings
public List<Float> yourList = new List<Float>(); //list of floats

*they need to be public variables so that you can see them in inspector.

In order to use Lists, you have to import System.Collections.Generic using this piece of code under your class definition:

using System.Collections.Generic;

Treat Lists as you would treat Arrays, but if you want to know the length of the list, use:

yourList.Count;

If you want to add an item:

yourList.Add(item)

*your item must be the same type of the List

if you want to remove an item:

yourList.Remove(item);
yourList.RemoveAt(index);
yourList.RemoveAll();
yourList.RemoveRange(startIndex, finalIndex);