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
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
Application.streamingAssetsPath (Also has an example, reading text)
Though I don't know why it wouldn't work with Resources.Load for you.
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
Follow this Question
Related Questions
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