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
1
Question by leoferreira · Jun 22, 2012 at 03:59 PM · missingreadtxt

Cannot read or write a txt file after build

I've create a txt file with some references and all I need us to read this file or write new lines on it. Before build, all tests in editor works fine. I can read the file and write withput problems.

The file is located in the Assets folder and I´m using "Application.dataPath" to reach it. After build and run, seems that both read and write functions stops to works. My big problem is the write function, as the read I can use a Resourses.Load and the write I only know to do with I/O streams.

Can someone give me a hint?

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 yeoldesnake 1 · Jun 22, 2012 at 04:25 PM 0
Share

Would you $$anonymous$$d posting your actual code here? There is not much we can suggest without it.

2 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by Bunny83 · Jun 22, 2012 at 05:34 PM

The Assets folder isn't available in your build. Look at the Application.dataPath documentation. In the editor it returns the Assets folder, in a build it's different.

Unity only includes assets in a build that are "used". If an asset is referenced from a scene object, it is included in the build, however "included" assets are not seperate files. They are available as an asset. If you have a txt file, it would be a TextAsset. TextAssets can only be read. You can't write to them since they are packed into the assetdatabase of your build.

You can of course read and write external files.
So the easiest "fix" for your problem is: Copy the txt file in the data folder of your build

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 leoferreira · Jun 22, 2012 at 11:21 PM 0
Share

Thanks for the info. This must be the reason. I'll try it as soon as possible!

avatar image Bunny83 · Jun 23, 2012 at 11:12 AM 2
Share

You asked in an answer:

Can you tell me how I can get the active user Documents folder, on Windows?

 Environment.GetFolderPath(Environment.SpecialFolder.Personal);

This will return the path to the users documents folder. It's just plain C# / .NET ;)

avatar image
3

Answer by amirabiri · Jun 22, 2012 at 06:37 PM

If you need a file to be available after build and you are referencing it from code (I.e in a way that Unity can't detect) you can put it in a Resources folder which are already aware of. However the file won't be available as it was originally, I.e it's not a standalone file in the build. It it merged into the bundle of assets and you can access its contents in a read only way. This because it's not meant for writing, it's an "asset" as the name implies, not a data or log file.

If you want to write to a file then that's not really an asset and you should simply use the normal file IO routines. You can use the Application class to find the current path if where the build is running from I.e the "installation" path). However you should also be careful with this: if the installation path is under program files then you need admin rights to write to the file. This should only be used for debugging. For production you should the user's home dir.

Comment
Add comment · 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

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

7 People are following this question.

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

Related Questions

Missing (sprite) errors appear after checking read/write box on a spritesheet........ 0 Answers

Problems with calculating binary file to 2D array 1 Answer

Work with XML hidden for the user? 1 Answer

System.IO documentation? 2 Answers

Best Storage Method 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