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 Thugann · Mar 08, 2016 at 10:27 AM · assetsloadtextassetpaths

How to load my text file

Hi,

I've read many topics on the subject but none of them helped me solve my problem.

I'm making an app for an android device and I need to use a text file to load assets into my scene. It works fine on PC but not on the target device.
I can't use Application.persistentDataPath to find the file because I can't side-load it, neither I can use Application.dataPath because it simply makes the app crash, and Application.streamingAssetsPath returns an inexisting directory path, according to my tests (yes, I had created a StreamingAssets folder in my project with my file in it).

I've tried to use Resources and load it in a TextAsset file but it always returns null. I've also tried to read what was in "./" (current directory) but it seems it is outside the apk.

Can anyone help me please?

List of things I tried:

 string filename = Application.dataPath+"/myFolder/myFile.txt";
 TextReader reader = new StreamReader(filename); 

 string filename = Application.streamingAssetsPath+"/myFile.txt";
 TextReader reader = new StreamReader(filename); 

 TextAsset file = Resources.Load<TextAsset>("myFile"); // with my file in a Resources folder 
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 Statement · Mar 08, 2016 at 08:50 PM

Try using StreamingAssets folder (it has to be directly under Assets, that is YourProject/Assets/StreamingAssets) unless I'm mistaken. Then, to load the file you can use WWW.

See

  • This other answer

  • Application.streamingAssetsPath (Also has an example, reading text)

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 Statement · Mar 08, 2016 at 08:50 PM 0
Share

Though I don't know why it wouldn't work with Resources.Load for you.

avatar image Thugann · Mar 09, 2016 at 03:35 PM 0
Share

Hi, thanks for answering me. I'll give another try to the Strea$$anonymous$$gAssets folder, but it didn't work the first time.

I hadn't seen the first link you posted though, after a quick overview it seems interesting, I'll give a feedback once I can try it again. Thanks :)

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

49 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

Related Questions

Loading data from File using TextAsset. Unable to output ÖÄÅ chars,Loading data from File using TextAsset, but unable ouput ÖÄÅ chars to UI.text 0 Answers

Dynamically Loading asset path issues 0 Answers

Can AssetDatabase be used to load and store assets from a standalone game? 0 Answers

How do I preload 3d assets? 0 Answers

Unet load testing 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