Loading Asset in Android using StreamingAssets and UnityWebRequest

I can’t believe how lack of documentation and support there is to load a simple file in Android platform… I know i have to put the file in StreamingAssets named folder, and then make a request using the UnityWebRequest class. This file is a binary file, which i saved using BinaryFormatter. How do i make this request? and then deserialize the response?

Hi,
the thing with the StreamingAssets folder is indeed a bit tricky. To retrieve a single file the web request procedure is enough.

var loadingRequest = UnityWebRequest.Get(Path.Combine(Application.streamingAssetsPath, "your.bytes"));
loadingRequest.SendWebRequest();
while (!loadingRequest.isDone) {
    if (loadingRequest.isNetworkError || loadingRequest.isHttpError) {
        break;
    }
}
if (loadingRequest.isNetworkError || loadingRequest.isHttpError) {

} else {
    File.WriteAllBytes(Path.Combine(Application.persistentDataPath , "your.bytes"), loadingRequest.downloadHandler.data);
}

It is easier with this little plugin:

When accessing multiple files and subfolders we had some problems ourselves. An interim solution is to pack elements of the StreamingAssets folder as file archive and unpack them on the device.