Problems With Saving On Android
Hello, I've followed the official Unity tutorial for saving and loading data. It works well enough for PC, but my target platform is Android. On Android saving stops working, any ideas as to why this happens?
public class PercentageTracker : MonoBehaviour {
public static PercentageTracker control;
public string[] Percentage;
private void Awake()
{
if (control == null)
{
DontDestroyOnLoad(gameObject);
control = this;
}
else if(control != this)
{
Destroy(gameObject);
}
}
private void OnEnable()
{
if (File.Exists(Application.persistentDataPath + "/PlayerInfo.dat"))
{
BinaryFormatter bf = new BinaryFormatter();
FileStream file = File.Open(Application.persistentDataPath + "/PlayerInfo.dat", FileMode.Open);
PlayerData data = (PlayerData)bf.Deserialize(file);
file.Close();
for (int i = 0; i < Percentage.Length; i++)
{
if (Percentage != null)
Percentage[i] = data.Percentage[i];
else
{
Percentage[i] = "Not Played";
}
}
}
}
private void OnDisable()
{
BinaryFormatter bf = new BinaryFormatter();
FileStream file = File.Create(Application.persistentDataPath + "/PlayerInfo.dat");
PlayerData data = new PlayerData();
for (int i = 0; i < Percentage.Length; i++)
{
if(Percentage!=null)
data.Percentage[i] = Percentage[i];
else Percentage[i] = "Not Played";
}
bf.Serialize(file, data);
file.Close();
}
}
[Serializable]
class PlayerData
{
public string[] Percentage = new string[10];
}
Comment
Best Answer
Answer by babijonas · Aug 03, 2017 at 09:47 AM
The answer is simple, On Player Settings, find the android settings panel, go to Other Settings and put "Write Permission" on External (SDCard)
Your answer
![](https://koobas.hobune.stream/wayback/20220612130553im_/https://answers.unity.com/themes/thub/images/avi.jpg)