Unity Android's StreamingAssets folder location

Viewed 6734

I use StreamingAssets for my Android Game, And would like add files in StreamingAssets folder after installation of APK, But I don't know where is the location of this folder.

Can you help me ?

2 Answers

You can not add or modify files that are inside the streaming assets folder after building since on almost all platforms the directory is read only. From the docs:

On many platforms, the streaming assets folder location is read-only; you can not modify or write new files there at runtime. Use Application.persistentDataPath for a folder location that is writable.

That said, on Android the filepath to the streaming assets is at "jar:file://" + Application.dataPath + "!/assets, from the same docs:

Android uses files inside a compressed APK /JAR file, "jar:file://" + Application.dataPath + "!/assets".

Do note that you can not access this file location through the standard C# File functions, but need to access it using a webrequest.

If you need a directory to store data during run time you need to use the Application.persistenDataPath instead. From the docs:

This value is a directory path where you can store data that you want to be kept between runs. When you publish on iOS and Android, persistentDataPath points to a public directory on the device. Files in this location are not erased by app updates. The files can still be erased by users directly.

You don't do this after build.

Create StreamingAssets directory inside Unity Editor in your Assets/ directory and add all your files there. They will be included in build automatically.

If you need this because of the .apk size limitation on Play Store then you can create an .obb file with all of the additional assets (including the ones in SteamingAssets directory). Check it here - https://docs.unity3d.com/Manual/android-OBBsupport.html.

Related