Saving/Loading Multiple Buildings With Binary Formatter

Hello!
I recently watched a video on youtube regarding saving and loading with the use of a binary formatter.
My goal is to make a resource management - colony building game, and i want to give the player the ability to save and load all of his buildings at the positions that he placed them. The way i have the system currently works fine, although, it only saves one building at a time. Is there a way to make it so it saves all of the placed buildings? I have provided the system’s code, so, if you can help, i would appreciate it, because i have been trying to fix it for hours.
Code:

Save System:

using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using UnityEngine;

public static class SaveSystem 
{
   public static void Save(BuildingScript B)
	{
		BinaryFormatter formattter = new BinaryFormatter();
		string path = Application.persistentDataPath + "/building.lol";
		FileStream stream = new FileStream(path, FileMode.Create);

		BuildingData data = new BuildingData(B);

		formattter.Serialize(stream, data);
		stream.Close();
	}

	public static BuildingData Load()
	{
		string path = Application.persistentDataPath + "/building.lol";
		if(File.Exists(path))
		{
			BinaryFormatter formatter = new BinaryFormatter();
			FileStream stream = new FileStream(path, FileMode.Open);

			BuildingData data = formatter.Deserialize(stream) as BuildingData;

			stream.Close();

			return data;
		}
		else
		{
			Debug.LogError("File Not Found");
			return null;
		}
	}

}

Building Data:

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

[System.Serializable]
public class BuildingData
{
	public int health;
	public int cost;
	public float[] position;

	public BuildingData(BuildingScript B)
	{
		health = B.health;
		cost = B.cost;

		position = new float[3];
		position[0] = B.transform.position.x;
		position[1] = B.transform.position.y;
		position[2] = B.transform.position.z;
	}

}

Building Script:

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

public class BuildingScript : MonoBehaviour
{
	public int health;
	public int cost;
}

Game Manager:

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

public class GameManager : MonoBehaviour
{
	public void Save()
	{
		SaveLoad.Save(GameObject.FindObjectOfType<BuildingScript>());
	}

	public void Load()
	{
		BuildingData data = SaveLoad.Load();

		GameObject.FindObjectOfType<BuildingScript>().health = data.health;
		GameObject.FindObjectOfType<BuildingScript>().cost = data.cost;

		Vector3 pos;
		pos.x = data.position[0];
		pos.y = data.position[1];
		pos.z = data.position[2];
		GameObject.FindObjectOfType<BuildingScript>().transform.position = pos;
	}
}

Your formatter can receive any data that is serializable. When you have a list, you can use an array and it will be Serializable. So you will need another script containing the array, let’s say AllBuildingsData:

[Serializable]
public class AllBuildingsData {
	public BuildingData[] buildingDatas;

	public AllBuildingsData(BuildingData[] buildingDatas) {
		this.buildingDatas = buildingDatas;
	}
}

Your Save function will then look something like this:

public static void Save(BuildingScript[] buildingScripts) {
		BinaryFormatter formattter = new BinaryFormatter();
		string path = Application.persistentDataPath + "/building.lol";
		FileStream stream = new FileStream(path, FileMode.Create);

		BuildingData[] buildingDatas = new BuildingData[buildingScripts.Length];
		for (int i = 0; i < buildingScripts.Length; ++i) {
			buildingDatas _= new BuildingData(buildingScripts*);*_

* }*

* AllBuildingsData data = new AllBuildingsData(buildingDatas);*

* formattter.Serialize(stream, data);*
* stream.Close();*
* }*
And in the Load function, you don’t get a BuildingData anymore, but a AllBuildingsData:
AllBuildingsData data = formatter.Deserialize(stream) as AllBuildingsData;
Bonus, unrelated to your question, but for better code! You should definitely cache your objects instead of calling 3 times the “FindObjectByType”. A call to this function is really expensive, so one call is better!
BuildingScript buildingScript = GameObject.FindObjectOfType();
buildingScript .health = data.health;
buildingScript .cost = data.cost;

@Mikaelgameryolo1 Hey could you please upload your updated code, i’m having the same problem trying to load all gameObject position and cant seem to solve it.