Constructor not working

Hello,

Im trying to create my GridData data in an Update/Awake function as a test but someitng has gone wrong. My rowData is Null. What am I missing please help.

using UnityEngine;
using System.Collections;

[System.Serializable]
public class GridData  {

    [System.Serializable]
    public struct rowData{
        public float[] colum;
    
    }
    public static int numRows =20;
    public static int numColums =20;
    public rowData[] rows = new rowData[numRows]; 


    //
    //Constructor
    public GridData(int x, int y){
        numRows =y;
        numColums = x;
        rowData[] rows = new rowData[numColums]; 
    }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class FractalMapData : MonoBehaviour {

    public int gridWidth =20;
    public int gridWHight =20;
    public GridData fractalGrid ;    
    void Update () {

        //TEST
        fractalGrid =new GridData(gridWidth,gridWHight);
        Debug.Log ("row" + fractalGrid.rows.Length); // row20
        Debug.Log ("colum" + fractalGrid.rows[0].colum.Length);// ERROR NullReferenceException: Object reference not set to an instance of an object
    }
}

The array colum is never assigned a size.

Is there some c# special method to do this ?. It really doesn’t like it

the same way you do with rowdata. You need to set the array size or you could use a list rather than an array.

Because there are a lot of them, you need to initialize them in a loop

for (int r=0;r<rows.Length;r++) {
rows[r].colum = new float[numColums];
}

However, you should be aware that you’re just writing a more complicated version of a two-dimensional array.

float[,] fractalGrid = new float[gridWidth, gridHeight];

Thanks for the reply

I love to use a two-dimensional array but I haven’t seen an example where anyone has successfully serialized it into the inspector. Getting this into the inspector is a huge pain, have seen anyone doing this ?