Mert Sevinc
Mert Sevinc

Reputation: 1027

Using assetbundles with streaming assets folder in Unity Android

I am loading a local assetbundle, which is located under streaming assets folder in my Unity game. I am using a simple code to do this:

Assetbundle assetbundle = AssetBundle.LoadFromFile(Path.Combine(Application.streamingAssetsPath,"myresource"));

This code is working perfectly fine but according to Unity documentation and forums, it should not work at all in Android due to fact the streaming asset will be zipped under a path like this: jar:// url.

The following statement is from Unity documentation: To read streaming Assets on platforms like Android and WebGL, where you cannot access streaming Asset files directly, use UnityWebRequest.

I have created an aab file and tested this code in ARMv7 and AMRv64 devices and it worked perfectly fine.

Unity's documentation is usually outdated so I really wonder if I should move this code to production or not.

Can someone shed a light on this ? Did they somehow fix this ?

Upvotes: 2

Views: 4396

Answers (2)

Stals
Stals

Reputation: 1603

Page on StreamingAssets does says that

To read streaming Assets on platforms like Android and WebGL , where you cannot access streaming Asset files directly, use UnityWebRequest. For an example, see Application.streamingAssetsPath.

but here is the reply from Unity on the forums (and a related "Fixed" Unity Issue), so the issue with bundles was fixed even in 5.3.* and you should be able to use AssetBundle.LoadFromFile on Android. StreamingAssets documentations seems to be correct, it just doesn't mention that there is a special case for reading assets with AssetBundle.LoadFromFile. LoadFromFile documentation also doesn't mention it, but uses streamingAssetsPath as an example.

There is also an alternative to use BetterStreamingAssets that builds the map of files and their offsets in the apk, and then passes the correct offset as one of the AssetBundle.LoadFromFile arguments, although not sure how it handles the compression in that case.

Upvotes: 0

aalmigthy
aalmigthy

Reputation: 1311

It is working as intended and you followed the documentation. Good job, no problem here.

In older times the recommended method was the WWW class, but this class is deprecated now. The documentation on this bit changed for Unity 2018.4, thats quite recent.

Upvotes: 2

Related Questions