- Home /
Difference between Application.persistantDataPath Vs Application.dataPath
As per my title suggest, I want to know difference between these two. Which one support in mobile device?
Answer by Bunny83 · May 05, 2016 at 09:48 AM
Like the documentation of dataPath shows it simply returns the path to your "game". This depends on the platform you run on.. But as a few examples:
in the editor it returns the path to the Assets folder inside your project folder.
in a standalone build it returns the path to the "data" folder where the game data is packed into Unity's custom asset format.
in an Android build it points to the APK file of your app.
The usage of dataPath has to be differenciated between "editor use" and "runtime use". In the editor you would use this path only in editor scripts. Runtime scripts should keep in mind what this path is used for in the build version. The Assets folder doesn't exist in a built game. At runtime you might want to use that path to manually load / access resources that you manually ship along with your build.
I just like to add the streamingAssetsPath here. The StreamingAssets are relatively new and allow you to put some files in the special "StreamingAssets" folder in your project. Those files won't be converted into Unity's asset format but simply shiped along with your build. The "streamingAssetsPath" returns the path to that folder at runtime. Keep in mind that there are some differences on some platforms. On Android those files will be inside a folder inside your APK archive. However the WWW class is able to read those with a special file path. Just read the docs if interested.
Finally there's the persistentDataPath. As the name suggests this returns a path where you might want to store files at runtime which should persist. Things like config files, savegame files, ... should be stored under that path. The actual path is different on each platform. It's usually based on the systems preferred storage location. On Windows for example it will be a folder in AppData.
Note: In the editor it also returns a path to a persistent folder, however that is usually only used when testing in the editor. So things created while testing in the editor won't show up at runtime. If you want to know the actual path, just use Debug.Log to print the path to the console.
If you have large amounts of web streamed data (images, videos, sounds, ...) you could use temporaryCachePath to store it temporarily for later use. Keep in mind to not store things there that can't be recovered from an alternate source.
@Bunny83, for mobile platform which one I need to use?
It depends on what you need the path for ^^. You only asked for the difference between those two things. You did not mention any usecase. Actually "dataPath" has less use for most applications. In most cases you probably want to use "persistantDataPath" (for storing and retrieving files) and "Strea$$anonymous$$gAssets" for things you want to ship with your game.
@Bunny83, thanks for your reply, I got my answer :)
Answer by abhinandand91 · May 05, 2016 at 10:50 AM
It depends on your requirement .. its not platform specific.. Of you want the Path starting from Assets directory then Application.dataPath
Your answer
Follow this Question
Related Questions
Path for Assets/Textures folder File in Android 2 Answers
Application.dataPath + "/Raw" not loading texture on iOS? 0 Answers
File Read-Write Error in iOS 1 Answer
File paths on Android 0 Answers
How do I find a folder I can write data to on Android? 3 Answers