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 twoface262 · Dec 15, 2012 at 06:11 PM · androidmobilefile-io

Android File-io?

Hello, I need help saving a text file to my android game

I'm using Application.persistentDataPath + "save.txt" but when I save it on my android phone I don't see the text file. It does have a folder on the phone for the game though. What am I doing wrong? Here is my function

 var directory = Application.persistentDataPath + "/save";

   

 function Start () {
 if (!System.IO.Directory.Exists(directory)){
       System.IO.Directory.CreateDirectory(directory);
       save2();
     }
 
 }
 
 var saved2 = Application.persistentDataPath + "/save/astroids.txt";

  function save2(){
     pla2 = GameObject.FindGameObjectsWithTag("planet");
     var sw1 = new StreamWriter(saved2);
     for( var pln1 : GameObject in pla2){
     
     var pls1 : planetbehave = pln1.GetComponent(planetbehave);
     sw1.WriteLine("---");
     sw1.WriteLine("" + pln1.transform.position.x + "\n");
     sw1.WriteLine("" + pln1.transform.position.z + "\n");
     sw1.WriteLine("" + pls1.health + "\n");
     sw1.WriteLine("" + pls1.sizes + "\n");
     }
     sw1.Flush();
     sw1.Close();
     }
Comment
Add comment · Show 8
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 bompi88 · Dec 15, 2012 at 06:19 PM 0
Share

First off, are you sure you are looking in the right folder? Try to write the Application.persistentDataPath to screen or something to check where the folder is.

avatar image bompi88 · Dec 15, 2012 at 06:23 PM 0
Share

This will also be helpful : http://answers.unity3d.com/questions/317048/android-writing-to-applicationpersistentdatapath.html

avatar image twoface262 · Dec 15, 2012 at 06:27 PM 0
Share

I'm sure I'm looking in the right folder, because it creates the folder. I have a root explorer on my phone and I still can't find the text file. It has all permissions set, and it should be writing the file, but it does not.

avatar image bompi88 · Dec 15, 2012 at 06:36 PM 0
Share

Have you checked both /data/data/com.mycompany.myapp/files and /mnt/android/data/*? What are your write access settings?

avatar image bompi88 · Dec 15, 2012 at 07:33 PM 1
Share

For the record, you are only calling save2() if the directory doesn't exists. The directory exists doesn't it? so it won't create that file until you remove the directory.

Show more comments

1 Reply

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

Answer by Bunny83 · Dec 16, 2012 at 01:22 AM

I used a lot of IO stuff on my android and even on the iPad. Never had any problems with it. However i don't have a rooted tablet and Unity stores the files in a directory which you can't access with a usual filebrowser. Are you sure that the file doesn't exist? You're actually not supposed to manipulate the files in the persistentDataPath outside of your app. Check from your app if the file exists, For my everything works as it should and even on the iPad it works the same way.

Comment
Add comment · Show 5 · 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 twoface262 · Dec 16, 2012 at 02:58 AM 0
Share

I'm going to add some debugging messages for gui text, and run it again. I'll let you guys know what if the game detects the file or not.

avatar image twoface262 · Dec 16, 2012 at 03:07 AM 0
Share

Yep, just adding this

function Update(){ if (System.IO.File.Exists(save1)){ exists = 1; }else{exists = 0;} } function OnGUI(){ if(exists == 1){ GUI.Label(Rect(Screen.width / 2, Screen.height / 2, 125,126), "Exists!");

}else{ GUI.Label(Rect(Screen.width / 2, Screen.height / 2, 125,126), "sorry bub!");

} }

And I'm getting the "sorry bub" message

avatar image twoface262 · Dec 16, 2012 at 03:25 AM 0
Share

In the log cat it's saying

"I/Unity (25983) IsolatedStorageException: Could not find a part of the path "/Saves/astroids.txt"

avatar image twoface262 · Dec 16, 2012 at 03:34 AM 0
Share

Never$$anonymous$$d. It was the old string getting stuck in the unity editor. >.< Gotta love unity. I fixed the problem and it's saving now! Thank you!

avatar image Fattie · Jan 25, 2016 at 11:07 PM 0
Share

it's amazing how many Android folks assume you can "see" the contents of Application.persistentDataPath :)

Those dudes have a "rooted-is-normal" culture :)

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

13 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

Related Questions

High score local [Android] 1 Answer

Saving items to a text file 1 Answer

Unity and ARMv6 with VFP, how to downgrade from Unity 4.x to Unity 3.5.x? How to use both Unity without errors and issues? 2 Answers

Load function not working propperly? 1 Answer

Simple Unity3d Facebook Integration? 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