public GameObject[] returnIncorrectPositions() { int numIncorrect = 0; for (int x = 0; x < 5; x++) { for (int y = 0; y < 5; y++) { GameObject objectpos = gridArray[x][y]; GridPosController gridPosController = objectpos.GetComponent <GridPosController>(); //Debug.Log("Position:" + gridPosController.positionX + "," + gridPosController.positionY); if (gridPosController.currentSquare != null) { SquareController squareController = gridPosController.currentSquare.GetComponent <SquareController>(); if (!squareController.IsPositionCorrect()) { numIncorrect++; } } } } GameObject[] incorrectArray = new GameObject[numIncorrect]; int i = 0; for (int x = 0; x < 5; x++) { for (int y = 0; y < 5; y++) { GameObject objectpos = gridArray[x][y]; GridPosController gridPosController = objectpos.GetComponent <GridPosController>(); //Debug.Log("Position:" + gridPosController.positionX + "," + gridPosController.positionY); if (gridPosController.currentSquare != null) { SquareController squareController = gridPosController.currentSquare.GetComponent <SquareController>(); if (!squareController.IsPositionCorrect()) { incorrectArray[i] = objectpos; i++; } } } } Debug.Log("Number incorrect:" + numIncorrect); return(incorrectArray); }