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 Ercova · May 20, 2021 at 06:49 AM · jsonsave datanulldatapath

About Json Datapath.

Hello Everyone.
I have This function. But the path is working (of cource) in only editor. How can i edit it for both editor and Build. And how can i check if there is the save file in that folder. Thank u so much in advance.

  [System.Serializable]
     public class SaveData
     {
         public int Shooting = ShootingManager.ShootingCounter;
     }
     public void Save()
     {
         SaveData data = new SaveData();
         string json = JsonUtility.ToJson(data);
         File.WriteAllText(Application.dataPath + "/save.txt", json);
     }
     public void Load()
     {
         if (File.Exists(Application.dataPath + "/save.txt"))
         {
             string savestring = File.ReadAllText(Application.dataPath + "/save.txt");
             SaveData data = JsonUtility.FromJson<SaveData>(savestring);
             ShootingManager.ShootingCounter = data.Shooting;
         }
     }                                                                                       
  
  
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Llama_w_2Ls · May 20, 2021 at 09:39 AM

Change Application.dataPath to Application.persistentDataPath. Application.persistentDataPath Documentation


A persistent data path is a path that can always be written and read to/from, on most platforms. Since the OS of Windows and Android are different, you can't use the same datapath on both platforms. They don't exist on both platforms.


However, a persistent data path is like a universal data path (in a sense), since it can always be located on any OS, by Unity. @Ercova

Comment
Add comment · Show 2 · 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 Ercova · May 20, 2021 at 11:54 AM 0
Share

Thank You so much for the answer but it was my bad i forgot to refence an object to the inspector and i thought it is about the persistentdatapath is not working all the time.. I've changed it to Application.persistentDataPath But at this time; When i quit the game the save data will be deleted but when i restart the game data will be there? what could be the problem :S @Llama_w_2Ls

avatar image Llama_w_2Ls Ercova · May 20, 2021 at 05:34 PM 0
Share

I don't understand your new issue.

When i quit the game the save data will be deleted

Does this mean that the data can't be seen in the editor? If the data is there when the game is loaded, then I don't see the problem.

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

119 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

Related Questions

Error writing to a json file: JsonException: Can't add a value here,Error writing to a json file, JsonException: Can't add a value here 1 Answer

Json Save Returns Empty(Code inside) 1 Answer

Saves on android, could not find file 0 Answers

Recieving Null when I should not be with JSONParse.js 0 Answers

Why are my null JSON variables returning fully initialized? 2 Answers


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