A common problem I’ve seen is PC builds not running properly on android when using binary to save data. I’ve also heard of people using Path.Combine to fix this issue. I’ve been struggling to find exactly where and how to put that line into the code without errors. If anyone could help that would be great. Thanks!
using UnityEngine;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Serialization;
public class UpgradeSave
{
public Upgrade _levels;
public UpgradeSave()
{
_levels = new Upgrade();
_levels.myUpgrades = new UpgradeData();
LoadUpgrade();
}
public void SaveUpgrade()
{
Debug.Log(Application.persistentDataPath);
FileStream file = new FileStream(Application.persistentDataPath + "/player.dat", FileMode.OpenOrCreate);
try
{
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(file, _levels.myUpgrades);
}
catch (SerializationException e)
{
Debug.LogError("There was an issue serilizing this data: " + e.Message);
}
finally
{
file.Close();
}
}
public void LoadUpgrade()
{
FileStream file = new FileStream(Application.persistentDataPath + "/player.dat", FileMode.Open);
try
{
BinaryFormatter formatter = new BinaryFormatter();
_levels.myUpgrades = (UpgradeData)formatter.Deserialize(file);
}
catch (SerializationException e)
{
Debug.LogError("There was an issue serilizing this data: " + e.Message);
}
finally
{
file.Close();
}
}
}