So,i used persisent data method to save files,and it works perfectly fine on every phone,even after an update,its still holds the file.But when you delete data ,and you start again,it doesnt save anymore…at all,it doesnt.Even if you update it it still doesnt save files.It happened on Huawei P10,and i can post a script,but its similar to the one in tutorial,same path for saving data.
If someone can help with it,it works perfect until you delete data on app
Please show your code, and how you are deleting the the data. Does it start to save after you restart the device?
Ill send you code now,anyways,it doesnt save the moment i deleted data,i opened setting for app,and on storage i told it to delete App Data
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
[System.Serializable]
class PlayerData
{
public int level1 = 0;
public int level2 = 0;
public int level3 = 0;
}
public class GameManager : MonoBehaviour {
public static GameManager manager;
public int level1=0;
public int level2=0;
public int level3=0;
// Use this for initialization
void Awake () {
if (manager == null) {
DontDestroyOnLoad (gameObject);
} else if (manager != this) {
Destroy (gameObject);
}
Load ();
}
public void Save()
{
BinaryFormatter bf = new BinaryFormatter();
FileStream file = File.Create(Application.persistentDataPath + “/playerInfo.dat”);
PlayerData data = new PlayerData ();
data.level1 = level1;
data.level2 = level2;
data.level3 = level3;
bf.Serialize (file, data);
file.Close ();
}
public void Load()
{
Debug.Log (“ItsWorking”);
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 ();
level1 = data.level1;
level2 = data.level2;
level3 = data.level3;
Debug.Log (“ALl is WORKING”);
}
}
}
Ill restart device and check
Ok,so it still doesnt save it,also it doesnt save after reinstallation of game,or both.I dont know if somethings wrong with the script,debug log works fine on editor,except that editor doesnt load files,its says its missing,but on phone it did load it
It has permission for storage too
How do you know it’s not saving? I don’t see a Debug.Log (“Not saving”)
I think it does…there are no errors for saving,there are for loading,why?
How could it load anything, if you just deleted the file? Also, your subject says “Doesn’t saved after clearing data”. How do you know it doesn’t save? Is there an error?
It was saving files,then i deleted app data in phones settings,afterwards i finished level and unlocked new one,i exited game to check if it saved,and it didnt,the second level was locked.Load and save functions are called trough other scripts
So it is NOT saving, you need to confirm. Put in the appropriate Debug.Log statements to ensure your Save method is being called and is successful.
I putted debug log on start of function and on the end of function Save,and its working properly on editor.Also on editor,load data is working too,no errors displayed
ok so like this,this is console from build games its all working
but it doesnt load complete script,i mean complete Load function,it only starts but it doesnt go pass if file,as shown in debug.log
You have if (File.Exists…) but of course it doesn’t exist if you just deleted it, so it goes no further. Please show your current code where you test that the Save is working. As a test, put another If (File.Exists…) at the end of your Save method to confirm.
Im verry stupid,i fixed it,on if command in load(); i had , instead of . That way it didnt work