private void InstantiateChunks(TERRAIN.ETerrain[,] _startTerrain)
    {
        terrainChunks       = new TerrainChunk[terrainDimension, terrainDimension];
        terrainChunkStorage = new MeshList <TerrainChunk>();
        int halfDim = GetTerrainDimCenter();

        for (int x = 0; x < terrainDimension; x++)
        {
            for (int z = 0; z < terrainDimension; z++)
            {
                terrainChunks[x, z] = new TerrainChunk(_startTerrain[x, z],
                                                       new Vector3(planetData.GetTerrainSize().x *(x - halfDim), 0, planetData.GetTerrainSize().y *(z - halfDim)) + currentCenter,
                                                       planetData.GetTerrainSize(),
                                                       this);
            }
        }



        terrainChunkStorage.SetCenter(terrainChunks[halfDim, halfDim]);
        //first do the middle line
        for (int x = 0; x < halfDim; x++)
        {
            terrainChunkStorage.AddLeft(-x, 0, terrainChunks[halfDim - x - 1, halfDim]);
            terrainChunkStorage.AddRight(x, 0, terrainChunks[halfDim + x + 1, halfDim]);
        }

        //the in parallel always do the line above and below in one set
        for (int y = 0; y < halfDim; y++)
        {
            terrainChunkStorage.AddAbove(0, y, terrainChunks[halfDim, halfDim + y + 1]);
            terrainChunkStorage.AddBelow(0, -y, terrainChunks[halfDim, halfDim - y - 1]);

            for (int x = 0; x < halfDim; x++)
            {
                terrainChunkStorage.AddLeft(-x, y + 1, terrainChunks[halfDim - x - 1, halfDim + y + 1]);
                terrainChunkStorage.AddRight(x, y + 1, terrainChunks[halfDim + x + 1, halfDim + y + 1]);
            }
            for (int x = 0; x < halfDim; x++)
            {
                terrainChunkStorage.AddLeft(-x, -(y + 1), terrainChunks[halfDim - x - 1, halfDim - y - 1]);
                terrainChunkStorage.AddRight(x, -(y + 1), terrainChunks[halfDim + x + 1, halfDim - y - 1]);
            }
        }

        ReloadChunkArrayFromStorage();

        currentStoragePosition = new Vector2Int(0, 0);
    }
    private void MoveLoadedSectionHorizontally(bool _right)
    {
        int column;

        if (_right)
        {
            column = terrainDimension - 1;
        }
        else
        {
            column = 0;
        }

        //move the center up by one step
        if (_right)
        {
            currentStoragePosition = new Vector2Int(currentStoragePosition.x + 1, currentStoragePosition.y);
        }
        else
        {
            currentStoragePosition = new Vector2Int(currentStoragePosition.x - 1, currentStoragePosition.y);
        }

        //try to load the currently stored chunks
        ReloadChunkArrayFromStorage();

        int halfDim = GetTerrainDimCenter();

        //check if any of the loaded chunks is still null and if so, generate them
        for (int i = -halfDim; i <= halfDim; i++)
        {
            if (terrainChunks[column, i + halfDim] == null)
            {
                //Debug.Log(terrainChunks[i + halfDim, row]);
                terrainChunks[column, i + halfDim] = new TerrainChunk(TerrainData.GetRandomTerrainByFrequency(),
                                                                      new Vector3(planetData.GetTerrainSize().x *(column - halfDim), 0, planetData.GetTerrainSize().y *i) + currentCenter,
                                                                      planetData.GetTerrainSize(),
                                                                      this);

                if (_right)
                {
                    terrainChunkStorage.AddRight(currentStoragePosition.x + halfDim - 1, currentStoragePosition.y + i, terrainChunks[column, i + halfDim]);
                }
                else
                {
                    terrainChunkStorage.AddLeft(currentStoragePosition.x - halfDim + 1, currentStoragePosition.y + i, terrainChunks[column, i + halfDim]);
                }
            }
        }

        //Reload the chunks after generating the missing ones
        //ReloadChunkArrayFromStorage();
    }