- Home /
Serialized data show information after load
I'm trying to get the serialized information after open the game, the gama save de variables or I thinks so because after Save the file data.dat is created I have the variables to load in static and the file is an DontDestroyOnLoad file. The Serialized save system look like these:
 //Guardar
 public void Save()
 {
     BinaryFormatter fb = new BinaryFormatter(); //Helper
     FileStream userData = File.Create(Application.persistentDataPath + "/data.dat"); //FileData route to create.
     UserMainData USERDATA = new UserMainData(); //Data to Serializar 
     //Data into the files.
     USERDATA.AirlineName = AirlineName;
     USERDATA.UserName = UserName;
     USERDATA.Mode = Mode;
     USERDATA.Hub = Hub;
     //Serializer
     fb.Serialize(userData, USERDATA);
     userData.Close();
     print("Saved"); //Process Ready Notification.
 }
 public void Load()
 {
     if(File.Exists(Application.persistentDataPath + "/data.dat")) //Verify if exit a Saved.
     {
         BinaryFormatter fb = new BinaryFormatter(); //Helper
         FileStream userData = File.OpenRead(Application.persistentDataPath + "/data.dat"); //Read the load.
         UserMainData USERDATA = new UserMainData(); //Data to deserializate.
         USERDATA = fb.Deserialize(userData) as UserMainData; //Data go to be de actual data.
         
         //Data loaded.
         USERDATA.AirlineName = AirlineName;
         USERDATA.UserName = UserName;
         USERDATA.Mode = Mode;
         USERDATA.Hub = Hub;
         print("Loaded"); //Process Ready Notification.
     }
     else
     {
         print("Cannot found existing game");
     }
 }
 public void NewGame()
 {
     if (File.Exists(Application.persistentDataPath + "/data.dat")) //Verify if exit a Saved.
     {
         File.Delete(Application.persistentDataPath + "/data.dat"); //Erase file.
     
     //Reestart data.
     AirlineName = "Unknow";
     UserName = "Unknow";
     Mode = 0;
     Hub = 0;
     print("Erased"); //Process Ready Notification.
     }else { print("Cannot found existing game"); }
 }
 }
 }
 [Serializable()] //Data ready to Serializar
 public class UserMainData : System.Object
 {
     public string AirlineName;
     public string UserName;
     public int Mode;
     public int Hub;
 }
and well, in the another scripts I'm writing the values to save in the static file, in the NewGame the game read the values correctly, but in exit and enter , when I load the game the values go to default again. The static values are these:
 public class UIsettings : MonoBehaviour
 {
     public static UIsettings Instance;
     //Data to save.
     public static string AirlineName = "Unknow";
     public static string UserName = "Unknow";
     public static int Mode = 0;
     public static int Hub = 0;
     //Autoload.
     public bool StartupLoad;
and I reference to read and write in other scripts in this mode:
         print(UIsettings.AirlineName);
         print(UIsettings.UserName);
         print(UIsettings.Mode);
         print(UIsettings.Hub);
I'm new in all these but, I have a big progress in my game and this, well... what I need to do so that it reads the saved data correctly when loading and does not revert to Default?
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                