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 TheCakeMaker · May 26, 2014 at 11:22 AM · textportingtextfile

Text not loading error

Hi. I've attempted to create code to list a number of question packs based on text files placed in resources. However when I run the build I get an error in the development console:

IsolatedStorageException: Could not find a part of the path "C:\Users\TCM\Desktop\2questionnaire\QuizEarlyPrototype\Assets\Resources\QuestionPacks\General.txt"

This is the scene's code.

         for( int i = 0; i < texts.Length; i++) {
             //Console.WriteLine (texts[i].name.ToString ()); 
             if(GUI.Button(new Rect(Screen.width - 400, 80+(80*i), 300, 70),texts[i].name.ToString(),PackGui))
                 {
                 //Debug.Log ("Done?");
                 string[] lines = File.ReadAllLines (@"Assets/Resources/QuestionPacks/" + texts[i].name.ToString() + ".txt");
               Application.LoadLevel (12);
                 }}

Any idea what might have caused this and how I would fix it? If I make an Iphone or android port would I have to use different pathways?

Comment
Add comment · Show 2
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 TheCakeMaker · May 26, 2014 at 04:09 PM 0
Share

Ok so i figured out what was going on. The text files weren't recreated in the build files so I just copied them into the assets/resources/etc folder in the build.

Is there anyway I can get Unity to automatically output the files ins$$anonymous$$d? It seems to load the text assets just fine but using ReadAllLines doesn't seem to work within builds

avatar image robertbu · May 26, 2014 at 04:13 PM 0
Share

What you are doing will not work for many builds. You will not have permission to copy the files to that folder. See my answer below for how you can load string across all platforms.

1 Reply

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

Answer by robertbu · May 26, 2014 at 04:12 PM

Paths like you specify in your code don't exist in a build. What you want to do is use Resources.Load() of a TextAsset. Rather than 'ReadAllLines()', you can use Split() to produce your array of strings from the TextAsset.text. Something like:

 TextAsset ta = Resources.Load ("QuestionPacks/" + texts[i].name.ToString(), typeof(TextAsset)) as TextAsset;
 string[] lines = ta.text.Split (new[] { '\r', '\n' }, System.StringSplitOptions.RemoveEmptyEntries);


Comment
Add comment · Show 4 · 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 TheCakeMaker · May 26, 2014 at 05:35 PM 0
Share

Thanks for the reply. I tried implementing that, however I received an overload error. The second argument requires System.File.Encoding.

I attempted to replace "typeof(TextAsset)" with "encoding:TextAsset" but it doesn't seem to work. I also tried using "as TextAsset" without the second arguement, but no luck there either.

Any advice? I haven't encountered Encoding before and I'm not sure how to approach it. I looked it up and haven't been able to find much.

avatar image robertbu · May 26, 2014 at 07:05 PM 0
Share

Sorry. Fingers getting ahead of my brain. I corrected the code in my answer.

avatar image TheCakeMaker · May 26, 2014 at 08:01 PM 0
Share

I wouldn't have realized I needed both "type of " and "as text asset". Thank you very much! You were a great help.

avatar image robertbu · May 26, 2014 at 08:25 PM 0
Share

There is a C# generic version that doesn't have to be cast:

  TextAsset ta = Resources.Load<TextAsset>("QuestionPacks/" + texts[i].name.ToString());

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

Check when text is done being printed? 1 Answer

I can't load all text files from resources 1 Answer

Is it possible to italicise GUI text without having italic font? 1 Answer

How to Instantiate an editable text field 0 Answers

Using Text file with .JS code written on it in webplayer? 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