Save array of GameObjects and their variables from an attached script under a parent

I have built a map editor for my game. It consists of an array of 3d blocks on a flat plane (x,0,z positions). Each of these blocks have a script attached to them that store the following values:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BlankTile : MonoBehaviour {

    public int x = 0;
    public int y = 0;
    public int tileStyle = 0;
    public int walkable = 0;
    public int wall = 0;
    public int spawnCreature = 0;
    public int spawnObject = 0;
    public int spawnInteractive = 0;
    public int triggerId = 0;


I have the values getting set fine, the blocks getting displayed and editable fine. But I want to save this data to a file (that isn’t easy to modify) to create all my game levels. So I need to save the location (also stored in the public x and y of the script) and be able to load them whenever I need to recreate the block locations and values. I would also like to give it a file name from the text box above Load and Save buttons Any help would be really appreciated.

This tutorial provides a good introduction to a basic save and load mechanism.

It is part 12 of a much larger series (which I highly recommend) so it assumes that you have already completed the previous 11 parts, though I think the information is explained well enough that one should be able to cherry-pick the information.

The method described is meant to be simple for learning purposes so is not the best way but there’s nothing really wrong with it either and should be sufficient for a semi-simple game.