Double Array (Custom Editor)

Basicly, what I am trying to do, is to display a double array as one.
Let me explain better.

→ First I have a list of strings

[HideInInspector]
    public List<string> ThemesList = new List<string>();

–>Then in the custom Editor I display it as a Drop Down Menu

GUIContent themeList = new GUIContent("Theme Mode");
    code.SelecteedThemeIndex = EditorGUILayout.Popup(themeList, code.SelecteedThemeIndex, code.ThemesList.ToArray());

(code.SelecteedThemeIndex being my choice, (everything works just fine here))

→ Now I have an array of Images

public Image[][] ThemeArray = new Image[5][];

’ 5 ’ being the maximum allowed number, it may change to any other

→ to display it, In custom Editor I use

Image[][] array = code.ThemeArray;
 
            code.showImages = EditorGUILayout.Foldout(code.showImages, "Themes List");
            if (code.showImages)
            {
                EditorGUI.indentLevel++;
                code.ObjectSize = Mathf.Max(0, EditorGUILayout.IntField("Size", code.ObjectSize));
 
                for (int i = 0; i < code.ObjectSize; i++)
                {
                    array[code.SelecteedThemeIndex] _= (Image)EditorGUILayout.ObjectField("Theme " + i, array[code.SelecteedThemeIndex]*, typeof(Image), true);*_

}

EditorGUI.indentLevel–;
}
I am trying to show in inspector an array of images, based on the selected Index.
(ex. on Index 0, there will be 3 images (img 1, img 2, img 3)
on Index 1, there will be also 3 images (img 1, img 4, img 5)
and I can switch the Index through the drop down menu, and the images(aka Arrays) will be swaped)
Until now, if I set the ObjectSize to anything but ’ 0 ’ it gives me this error
[179191-2021-04-13-10-09-58.png|179191]*_
In Visual Studio (2019) there are no errors.
If you need the full code there it is:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEngine.UI;

public class ThemesCoder : MonoBehaviour
{
[HideInInspector]
public List ThemesList = new List();
[HideInInspector]
public List Theme = new List();
[HideInInspector]
public int SelecteedThemeIndex = 0;
[HideInInspector]
public bool showList = false;
[HideInInspector]
public bool showImages = false;
[HideInInspector]
public Image[][] ThemeArray = new Image[5][];
[HideInInspector]
public int ObjectSize = 0;
[HideInInspector]
public int size = 0;

[CustomEditor(typeof(ThemesCoder))]
//[CanEditMultipleObjects]
public class ThemeCoderEditor : Editor
{
public override void OnInspectorGUI()
{
base.OnInspectorGUI();

DrawInspector();
}

public void DrawInspector()
{
ThemesCoder code = (ThemesCoder)target;

#region Themes Modes List

code.showList = EditorGUILayout.Foldout(code.showList, “Themes List”);
if (code.showList)
{
EditorGUI.indentLevel++;
List list = code.ThemesList;
code.size = Mathf.Max(0, EditorGUILayout.IntField(“Size”, list.Count));

while (code.size > list.Count)
{
list.Add(null);
}

while (code.size < list.Count)
{
list.RemoveAt(list.Count - 1);
}

for (int i = 0; i < list.Count; i++)
{
list = EditorGUILayout.TextField("Theme " + i, list*);*
}
EditorGUI.indentLevel–;
}
#endregion

#region Curent Mode
GUIContent themeList = new GUIContent(“Theme Mode”);
code.SelecteedThemeIndex = EditorGUILayout.Popup(themeList, code.SelecteedThemeIndex, code.ThemesList.ToArray());
#endregion

EditorGUILayout.Space();

#region Theme Game Object

Image[][] array = code.ThemeArray;

code.showImages = EditorGUILayout.Foldout(code.showImages, “Themes List”);
if (code.showImages)
{
EditorGUI.indentLevel++;
code.ObjectSize = Mathf.Max(0, EditorGUILayout.IntField(“Size”, code.ObjectSize));

for (int i = 0; i < code.ObjectSize; i++)
{
array[code.SelecteedThemeIndex] = (Image)EditorGUILayout.ObjectField("Theme " + i, array[code.SelecteedThemeIndex], typeof(Image), true);
}

EditorGUI.indentLevel–;
}
#endregion
}
}
}
*
Edit: I will use sprites, not Images as arrays, shall be no difference in the code.
I tried aproaching this problem with a struct:
[System.Serializable]
public struct SpriteArray
{
public Sprite[] Sprites;
}
Then declaring it like this
[HideInInspector]
public SpriteArray[] ThemeArray;
Using the next loop to show it
for (int i = 0; i < code.ObjectSize; i++)
{
array[code.SelecteedThemeIndex].Sprites = (Sprite)EditorGUILayout.ObjectField("Theme " + i, array[code.SelecteedThemeIndex].Sprites*, typeof(Sprite), true);*
}
Still I get no errors in VS, only when I change the ObjectSize to anything but 0 I get the same error as above._

Solved, Just when declaring the array make it to null.
exmple code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEngine.UI;

public class ThemesCoder : MonoBehaviour
{
    [HideInInspector]
    public SpriteArray[] ThemeArray = null;
    [HideInInspector]
    public List<string> ThemesList = new List<string>();
    [HideInInspector]
    public List<Image> Theme = new List<Image>();
    [HideInInspector]
    public int SelecteedThemeIndex = 0;
    [HideInInspector]
    public bool showList = false;
    [HideInInspector]
    public bool showImages = false;
    
    [HideInInspector]
    public int ObjectSize = 0;
    [HideInInspector]
    public int size = 0;

    [CustomEditor(typeof(ThemesCoder))]
    //[CanEditMultipleObjects]
    public class ThemeCoderEditor : Editor
    {
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            DrawInspector();
        }

        public void DrawInspector()
        {
            ThemesCoder code = (ThemesCoder)target;

            #region Themes Modes List
           
            
            code.showList = EditorGUILayout.Foldout(code.showList, "Themes List");
            if (code.showList)
            {
                EditorGUI.indentLevel++;
                List<string> list = code.ThemesList;
                code.size = Mathf.Max(0, EditorGUILayout.IntField("Size", list.Count));

                while (code.size > list.Count)
                {
                    list.Add(null);
                }

                while (code.size < list.Count)
                {
                    list.RemoveAt(list.Count - 1);
                }

                for (int i = 0; i < list.Count; i++)
                {
                    list _= EditorGUILayout.TextField("Theme " + i, list*);*_

}
EditorGUI.indentLevel–;
}
#endregion

#region Curent Mode
GUIContent themeList = new GUIContent(“Theme Mode”);
code.SelecteedThemeIndex = EditorGUILayout.Popup(themeList, code.SelecteedThemeIndex, code.ThemesList.ToArray());
#endregion

EditorGUILayout.Space();

#region Theme Game Object

SpriteArray[] array = code.ThemeArray;

code.showImages = EditorGUILayout.Foldout(code.showImages, “Themes List”);
if (code.showImages)
{
EditorGUI.indentLevel++;
code.ObjectSize = Mathf.Max(0, EditorGUILayout.IntField(“Size”, code.ObjectSize));

for (int i = 0; i < code.ObjectSize; i++)
{

array[code.SelecteedThemeIndex].Sprites = (Sprite)EditorGUILayout.ObjectField("Theme " + i, array[code.SelecteedThemeIndex].Sprites*, typeof(Sprite), true);*

}
EditorGUI.indentLevel–;
}
#endregion
}
}
}

[System.Serializable]
public struct SpriteArray
{
public Sprite[] Sprites;
}