Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by Darkeriol · Aug 03, 2017 at 01:50 PM · updateeditpersistentdatapath

Can I add or remove values and variables in persistentDataPath once it's been created?

Can I remove or add new values and variables to persistentdatapath when I update an application? If yes, how I can do it?

Also can I search for the file that was created to save the data and edit the values in it?

Comment
Add comment · Show 1
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
avatar image nt314p · Aug 03, 2017 at 02:42 PM 0
Share

Could you post your code so that we can get an idea of what you are doing?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Darkeriol · Aug 03, 2017 at 03:10 PM

 public class SaveLoad : MonoBehaviour {
 
     public void Save()
     {
         BinaryFormatter bf = new BinaryFormatter ();
         FileStream file = File.Create (Application.persistentDataPath + "/playerInfoITH.dat");
 
         PlayerData data = new PlayerData();
         data.lang = Data.lang;
         data.music = Data.music;
 
         data.uwarriortest = Data.uwarriortest;
         data.uwarrior = Data.uwarrior;
         data.uarcher = Data.uarcher;
 
         data.coin = Data.coin;
 
         bf.Serialize (file, data);
         file.Close ();
     }
 
     public void Load()
     {
         if (File.Exists (Application.persistentDataPath + "/playerInfoITH.dat"))
         {
             BinaryFormatter bf = new BinaryFormatter ();
             FileStream file = File.Open (Application.persistentDataPath + "/playerInfoITH.dat", FileMode.Open);
             PlayerData data = (PlayerData)bf.Deserialize (file);
             file.Close ();
 
             Data.lang = data.lang;
             Data.music = data.music;
 
             Data.uwarriortest = data.uwarriortest;
             Data.uwarrior = data.uwarrior;
             Data.uarcher = data.uarcher;
 
             Data.coin = data.coin;
         }
     }
 
     public void Delete()
     {
         if (File.Exists (Application.persistentDataPath + "/playerInfoITH.dat"))
         {
             File.Delete (Application.persistentDataPath + "/playerInfoITH.dat");
         }
     }
 }
 
 [Serializable]
 class PlayerData
 {
     //Settings
     public int lang;
     public bool music;
 
     //Characters
     public bool uwarriortest;
     public bool uwarrior;
     public bool uarcher;
 
     public int coin;
 }

My question is whether I can add new variables or remove them to the PlayerData class when I update my application.

Example:

 class PlayerData
 {
     //Settings
     public int lang;
     public bool music;
 
     //Characters
     public bool uwarriortest;  //Can I remove it?
     public bool uwarrior;
     public bool uarcher;
     public bool uwizard;   // Can I add it?
 
     public int coin;
 }

Comment
Add comment · Show 3 · Share
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
avatar image nt314p · Aug 04, 2017 at 01:01 AM 0
Share

I think you can, just make sure to delete the old variable from the playerdata to avoid "clutter".

avatar image Darkeriol nt314p · Aug 04, 2017 at 11:31 AM 0
Share

Is there a script that allows me to delete the variables I do not need? Because if I try to delete it in the PlayerData class script once the variable has been created by an earlier update, it gives me an error.

SerializationException: Field "uwarriortest" not found in class PlayerData

avatar image nt314p Darkeriol · Aug 04, 2017 at 09:04 PM 0
Share

Is there a reason you are using .dat files? In the past, I have used playerprefs and they work just fine for me. They are also much easier to use.

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

68 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

Related Questions

PersistentData erased with iOs update 0 Answers

Press Escape, quit game if variable is false otherwise... How? 1 Answer

Optimizations: Should I use Update or FixedUpdate? Could you help me optimize rotations? 1 Answer

Start() and Update() execution issue 6 Answers

Stuck with scaling an object 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