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 /
avatar image
0
Question by fr0stsp1k3 · Sep 05, 2018 at 01:58 PM · androidunity5wwwstreamingassets

StreamingAssets - reading from file on android

this is not a dupe - but the closest thing i could find is https://answers.unity.com/questions/1308831/reading-file-from-streamingassets-android.html

I get that the optimal way to do data is during runtime - and i also specifically read multiple places that resources.load() is not the way to go and to use streamingassets, so thats the road i go down, also because i want to keep a very specific file structure.


The reason: currently in there's going to be, a -lot- of individual files with specific naming conventions that i need to be able to read through and pick out, and get specific data, also to help remove the entire need for loading the data in, as that would not be viable, with 100k files. And writing in these data hardcoded in is also not viable, for obvious reasons.


Here's what im currently doing, which may be wrong. This is my first android built unity game.

the start of my data script where i determine platform and path.

   cObject = GameObject.Find("CoreScripts");
         cScript = cObject.GetComponent<CoreScript>();
 
         Debug.Log("Started Data Script");
         if (Application.platform == RuntimePlatform.Android)
         {
             currentPlatform = "android";
             toDataPath = "jar:file://" + Application.dataPath + "!/assets/Data/";
             cScript.SetBodyTextDisplay("UITextBox", "Canvas", "Currently using Android build");
         }
         else if (Application.platform == RuntimePlatform.WindowsPlayer)
         {
             currentPlatform = "windows";
             toDataPath = Application.streamingAssetsPath + "/Data/";
             cScript.SetBodyTextDisplay("UITextBox", "Canvas", "Currently using Windows build");
         }
         else if (Application.platform == RuntimePlatform.WindowsEditor)
         {
             currentPlatform = "editor";
             toDataPath = Application.streamingAssetsPath + "/Data/";
             cScript.SetBodyTextDisplay("UITextBox", "Canvas", "Currently using Editor build");
         }

here's where i, attempt, to read the data, which currently does not seem to function.

   public IEnumerator ReadData(string pathTo, string fileName) {
         string tempData = "null";
         fileName = fileName + dataExtension;
         cScript.SetBodyTextDisplay("UITextBox", "Canvas", "Test1: "+Application.streamingAssetsPath);
         cScript.SetBodyTextDisplay("UITextBox", "Canvas", "Test2: "+pathTo + fileName);
 
         if (currentPlatform.Equals("android"))
         {
             WWW read = new WWW(pathTo+fileName);
             while (!read.isDone)
             {
                 yield return null;
             }
             tempData = read.text;
             read.Dispose();
             cScript.SetBodyTextDisplay("UITextBox", "Canvas", "Reading: " + pathTo + fileName + " - " + tempData);
         }
         else
         {
             StreamReader read = new StreamReader(pathTo + fileName);
             tempData = read.ReadLine();
             cScript.SetBodyTextDisplay("UITextBox", "Canvas", "Reading: " + pathTo + fileName + " - " + tempData);
             Debug.Log("Reading: " + pathTo + fileName + " - " + tempData);
             read.Close();
         }
             //hmm, return string? think... tempData
         yield return null;
     }

I am aware of the access issue, but i should none the less be able to read from said file, correct? (also, i am doing a coroutine for said ienumerator)


What exactly can i do about this? Because i've been reading into it, trying different things, and varius different paths, none seem to work (i have seen some people use path.combine syntax which i wasnt sure might be the issue. I am also defering directly to the unity

https://docs.unity3d.com/Manual/StreamingAssets.html

In terms of finding the correct path. As you can see in the examples above.


Also i find it incredibly tedious in terms of saving/storing data on android? Is it just me or does it seem like there's absolutely 0 good ways to do any data at all properly on said device?

Also note, everything does work on a normal windows build.

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

0 Replies

· Add your reply
  • Sort: 

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

221 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 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 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 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 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

How to read xml file on Android using www and StreamingAssets? 2 Answers

Loading an image from streamingassets fails every time on Android 1 Answer

I can't figure out how to use www to copy a file / very confused about porting to android... 0 Answers

how do you correctly copy a jpg file from streaming assets folder using www? 1 Answer

Problem using StreamingAssets on Android 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