Saving an Array list trouble

I’ve been following this tutorial on creating an inventory system. I’m at a part of the tutorial where he is speaking about saving the inventory. The way he does this is by saving it to the playerprefs. However I use a different method than to this but I cant quite seem to succeed in saving my inventory using it. Most likely because I’m not skilled enough. So I’m reaching out to the community for help!

His code of doing it:

    void SaveInv()
    {
           for (int i = 0; i < inventory.Count; i++)
          {
                  PlayerPrefs.SetInt("Inventory " + i, intentory*.itemID);*

}
}
void LoadInv()
{
for (int i = 0; i < inventory.Count; i++)
{
Inventory = PlayerPrefs.GetInt("Inventory " + i, -1) >= 0 ? database.items[PlayerPrefs.GetInt("Inventory " + i)] : new Item();
}

}

Now my code looks like this. I dont want to do it through PlayerPrefs.
public void SaveGame()
{
// Debug.Log("Saved at: " + "X: " + SavePos.x + " " + "Y: " + SavePos.y + " " + "Z: " + SavePos.z);

BinaryFormatter bf = new BinaryFormatter();
FileStream file = File.Create(Application.persistentDataPath + “/playerInfo55.dat”);

PlayerData data = new PlayerData();
// ITEMS TO SAVE

data.itemIDs = new int[inventory.Count];
for (int i = 0; i < inventory.Count; i++)
{
data.itemIDs = inventory*.itemID;*
}

bf.Serialize(file, data);
file.Close();
}

public void LoadSave()
{
if (File.Exists(Application.persistentDataPath + “/playerInfo55.dat”))
{
BinaryFormatter bf = new BinaryFormatter();
FileStream file = File.Open(Application.persistentDataPath + “/playerInfo55.dat”, FileMode.Open);
PlayerData data = (PlayerData)bf.Deserialize(file);
file.Close();

// ITEMS TO LOAD

for (int i = 0; i < inventory.Count; i++)
{
inventory_.itemID = data.itemIDs*;
}*_

}
}
Thanks in advance!
Ask anything and I’ll explain what I can! :slight_smile:

First of all you are loading and saving to different file! playerInfo53.dat vs playerInfo55.dat. Are you sure it’s properly set?