- Home /
Streaming Assets or Persistent Data Path for reading files after build.
Hi everyone! I'm making a simple 2d game and in that I need to load images and some audio files from a folder instead of resources. I've heard that streaming assets or persistent data path can be used but I don't know which one will be suitable for me. I've some files already within the persistent data path folder and I want them to be built alongside the game i.e. they come with the game when it is built and are automatically placed in the persistent data path of the computer on which the game is installed. But I've heard that it's not possible and some told me to use streaming assets. So please help which method should I use.
It is unclear what you would like to do: first you write "load images and some audio files from a folder ins$$anonymous$$d of resources", but then "I want them to be built alongside the game".
By default whatever data files you place under the Assets folder (and its subfolders), it will be built into the game, and you can access them in various ways (assigning in Editor, using Resources.Load()
, etc.). You don't need Strea$$anonymous$$gAssets or persistent data path for that. On the other hand, if you want to load files added after the project is built, you need to handle that differently, probably accessing the persistent data path.
So which one is it, do you want the resources come with the game, or do you want to add resources after building? Or explain in more detail what you would like to achieve.
Okay just listen to this, I have audio and images inside the persistent data path folder. Whenever my game runs it actually gets the images and audio files from persistent data path. What I want is that all of my images and audio files that are present inside the persistent data path to be built alongside the game and copied to persistent data path of the computer on which the game is run. I want to get data from a folder besides the resources so that's why I asked the question because i'm not sure which one will do the job.
Answer by Harinezumi · May 01, 2018 at 10:06 AM
OK, I think now I understand now what you mean. To be sure I understood you correctly, you would like to load images and audio from a folder that is not "encoded" with the application, so that they are visible and maybe even changeable?
If you provide the files yourself, then the StreamingAssets folder is what you want (the persistent data path is rather for storing data between play sessions, for example for save files or data generated through gameplay). The StreamingAssets folder is copied as-is into the build, accessible from the game, but from the file system as well. Here is a great tutorial explaining how to use it for various purposes, including customising your game:
https://www.raywenderlich.com/165809/using-streaming-assets-unity
yes that's exactly what I want. But what if I build game for android, where would these assets go and how will I access them?
A quick google search for "unity strea$$anonymous$$g assets folder on android" gave all the answers ;)
Basically on Android you use a WWW operation (which is more general than calls to System.IO) to access a file, constructing the path like this: path = "jar:file://" + Application.dataPath + "!/assets/";
. See documentation: https://docs.unity3d.com/$$anonymous$$anual/Strea$$anonymous$$gAssets.html
And the first two answers here give you code examples how it can be done (they will need to be modified to suit your needs).
Thank you so much, I'll try that and see if that works.
What is the benefit of using Application.strea$$anonymous$$gAssetsPath over Application.dataPath?
Your answer
Follow this Question
Related Questions
Opening data file from asset folder 2 Answers
AppleTV persistanceDataStorage 0 Answers
loading Images from streaming assets in Android 0 Answers
Can't transfer file from datapath to devices 1 Answer
Application.CaptureScreenshot() does not save any image on Android while it does on Editor! 0 Answers