Updating Array inside a List


I’m currently facing a problem regarding update values of several arrays inside a list.
The basic setup is the following: a List containing 3 arrays each comprised of 16 float numbers.
My problem is regarding the update of the each array, whenever I update one, it also affects ALL other arrays present in the list, something that I don’t want to happen. The update of each array is made by calling the FindHomography function.

The code is as follows (for a matter of simplicity I omitted most of the code, however I can post more if needed):

    public float[] matrix = new float[16];
    public const int arraySize = 16;
    public List<float[]> matrixList;
    void Start () {
        void InitMatrixList(){
        		int numPlanes = manager.numExistPlanes;
        		matrixList = new List<float[]>();
        		for(int i = 0; i <= numPlanes; i++){
        			Debug.Log ("Matrix added");
        void LateUpdate () {
        planeMatrixNum = manager.activePlaneNum;
        matrix = matrixList[planeMatrixNum]; 
        FindHomography(ref source, ref destination, ref matrix);

Also I don’t really know if it’s relevant since I have very little experience but these matrix values are used within a shader (not written by me).

Most things are by reference in C#. You are creating only one matrix and assigning that same matrix to all of your entries in your list. Change line 14 to:

matrixList.Add(new float[16]);

And you can get rid of the ‘new float[16]’ on line 1.