MutliDimensionnal Array public size

Hello
I got a problem with my multiDim arrays sizes.
As it’s a public var, The size is fixed in editor, no matter how long i initialize it with
public Map myMap = new Map[4];
if myMap is set to 3 in editor, it will be a size of 3 no matter what, and of course I need to change this values at start.
here’s my code :

[System.Serializable]
	public class Map { 
		public int[] intArray = new int[0];

		public int this[int index] {
			get {
				return intArray[index];
			}
			
			set { 
				intArray[index] = value; 
			}
		}

		public int Length {
			get {
				return intArray.Length;
			}
		}

	}
	public Map[] myMap = new Map[4];//(size fixed in Editor)

void Start () {

	for (int i=0; i<myMap.Length; i++) {
		myMap*.intArray = new int[myMap.Length]; //creates a 4x4 map*
  •   	}*
    

}

It’s not really clear what you actually want. If you make your class serializable you usually don’t initialize it manually at all since the point of serializing a class / variable is to set it in the inspector. The inspector will create / change all required instances on the fly for you when you editing the inspector.

If you really want to initialize it manually you shouldn’t make it a serializable class.

To initialize your structure as an NxN array you have to do this:

public Map[] myMap;
public int gridSize;
void Start ()
{
    myMap = new Map[gridSize];
    for (int i=0; i<myMap.Length; i++)
    {
        myMap *= new Map();*

myMap*.intArray = new int[gridSize];*
}
}
This is pure C# and nothing Unity special. If you create an array of a class type the elements of the array will be null initially. You have to create your 4 “Map” instances before you can use them. As said, when marking the class as serializable the inspector will create those instances for you when you resize the array in the editor. Of course the inspector creates them at edit time and the data is stored (and restored at runtime) with the serializaion system.

initialize your map size inside Start() instead.

so something like

public Map[] myMap;
public int mapSize;

void Start(){
 myMap = new myMap[mapSize];
}