Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by LordYuuta · Oct 08, 2020 at 04:52 AM · serializationsave dataserializeserializablegeneral

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?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

146 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Saving Non-Prefab Data During Editor Play 0 Answers

BinaryFormatter - saving and loading a list containing sprites. 0 Answers

Private Variables Serialised By Default 2 Answers

Save and Load all spawned objects in their position using array 1 Answer

UnityEngine.GameObject not marked as Serializable? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges