This happened after I shrunk down my script to just one function for refreshing the saved data. The Unity Console doesn’t give me any error after I saved the script. This issue shows up when I run my app in Unity. I tried to change the script execution order, but no luck either. I copied the code from my previous script; it worked fine recently.
using System.Collections;
using UnityEngine;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
public class UserInfo : MonoBehaviour {
public string _UserName;
public ArrayList SavedGamerID;
public string ServerName;
void Start(){
this.gameObject.GetComponent<DownloadAndUpLoadUserData>().DownloadLocalUserData();
RefreshSavedUserInfo();
}
public void RefreshSavedUserInfo() {
if (File.Exists(Application.persistentDataPath + "/UserInfo/UserAccount.save"))
{
BinaryFormatter bf = new BinaryFormatter();
FileStream file = File.Open(Application.persistentDataPath + "/UserInfo/UserAccount.save", FileMode.Open);
UserData data = (UserData)bf.Deserialize(file);
_UserName = data.UserName;
SavedGamerID = new ArrayList(data.GamerInfo);
file.Close();
}
}
public void SaveUserInfo() {
FileStream file;
BinaryFormatter bf = new BinaryFormatter();
file = File.Create(Application.persistentDataPath + "/UserInfo/UserAccount.save");
UserData data = new UserData();
data.UserName = _UserName;
data.GamerInfo = new ArrayList(SavedGamerID);
bf.Serialize(file, data);
RefreshSavedUserInfo();
}
}