Home > front end >  Unity, JSON file - Android problem, can't find my JSON file
Unity, JSON file - Android problem, can't find my JSON file

Time:09-17

I wrote a script that allows you to read and write to a json file. As long as I tried the script in unity editor, I didn't have any problems. But when I switched to installing the application on an Android device, I can't find my json file.

The json file is called "playerData.json" and has been placed in a folder called "playerData.json".

This is the code for the path of the json file (working on unity but not working on android)

path = Application.streamingAssetsPath   "/playerData.json";

I tried using this string of code to get the code to work on android as well, but there is no way to get it to work.

path = System.IO.Path.Combine(Application.streamingAssetsPath, "/playerData.json");

I only wrote the line concerning the path as my android device cannot find the JSON file. Thanks everyone for the help!

CodePudding user response:

Application.streamingAssetsPath does not work on Android and WebGL

It is not possible to access the StreamingAssets folder on WebGL and Android platforms. No file access is available on WebGL. Android uses a compressed .apk file. These platforms return a URL. Use the UnityWebRequest class to access the Assets.

There is a workaround though as mentioned using UnityWebRequest, can find an example in this Unity Answer

  • Related