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 awplays49 · May 23, 2015 at 11:20 AM · buildsave

Building game deletes save data file - how do i keep the file when saving?

I keep a save data txt file in the data folder. I need to have this kept when i build the game. Help?

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

Answer by Fornoreason1000 · May 23, 2015 at 12:16 PM

Simple just load/write your save from outside the build, e.g MyDocuments/UnityGameSaves/Save001.txt

Or even jsut make a folder called "Saves" outside of the builds Data folder, and put your save in that, you want to keep your saves out of the data folder.

Another but long and difficult way is to create a custom build editor script that loads all your saves, builds your game , then saves them all again.

Comment
Add comment · Show 9 · 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 awplays49 · May 23, 2015 at 12:26 PM 0
Share

why isnt this directory working though?

     string filePath = "C:/Users/../AppData/Roa$$anonymous$$g/Evil Squirrel/Testing Project/Save Data";
avatar image awplays49 · May 23, 2015 at 12:37 PM 0
Share

whole code:

 using UnityEngine;
 using UnityEngine.UI;
 using System.Collections;
 using System.IO;
 
 public class Test : $$anonymous$$onoBehaviour {
     
     void Update () {
         string filePath = "C:/Users/../Evil Squirrel/Save Data/Save";
         if (File.Exists (filePath))
         {
             Debug.Log ("File Exists");
             if (Input.Get$$anonymous$$eyDown ($$anonymous$$eyCode.W))
             {
                 WriteFile (filePath);
             }
             if (Input.Get$$anonymous$$eyDown ($$anonymous$$eyCode.R))
             {
                 ReadFile (filePath);
             }
         }
     }
     
     void WriteFile (string functionPath) {
         StreamWriter sw = new StreamWriter (functionPath);
         sw.WriteLine (functionPath);
         Debug.Log (sw);
         sw.Flush ();
         sw.Close ();
     }
     
     void ReadFile (string functionPath) {
         StreamReader sr = File.OpenText (functionPath);
         if (sr != null)
         {
             Debug.Log (sr);
             GetComponent <Text> ().text = "" + sr;
         }
     }
 }
         
avatar image Fornoreason1000 · May 23, 2015 at 01:33 PM 0
Share

I tested with this

 void Update () {
         if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Q))
         {
             var functionPath = "C:/Users/"+Envirmoent.UserName+"/Appdata/Roa$$anonymous$$g/IRON UNITY/Save.sav";
             var dirPath = "C:/Users/"+Environment.UserName"+/Appdata/Roa$$anonymous$$g/IRON UNITY";
 
             print("Blitzing for 6 seconds!");
             if (!Directory.Exists(dirPath))
             {
                 Directory.CreateDirectory(dirPath);
             }
             if (!File.Exists(functionPath))
             {
                 using (File.Create(functionPath))
                 {
 
                 }
             }
             StreamWriter sw = new StreamWriter(functionPath);
             sw.WriteLine(functionPath);
             Debug.Log(sw);
             sw.Flush();
             sw.Close();
             StartCoroutine(OnBlitz());
         }
     }


I Open my Windows Explorer and navigated to where the file was going to appear, then watched. I created the file in the editor, then i built it. the Save file was untouched. so i tried saving in the build. nothing happens.

avatar image awplays49 · May 23, 2015 at 01:40 PM 0
Share

file.exists doesnt fire for me. i even tried using just

 if (File.Exists ("C:/Users/.."))
avatar image Fornoreason1000 · May 23, 2015 at 01:47 PM 0
Share

I tried it with your "/.." and then the file didn't save at all (I've actually never seen that in practice). Have you tried using Environment.UserName? or typing the username directly?

Show more comments

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

20 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

Related Questions

Distribute terrain in zones 3 Answers

How can I access an external file within the same folder as the built .exe? 2 Answers

Save and Load in the build 0 Answers

Default Save directory 2 Answers

Script changes layer order. Unity changes it back on build. 0 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