Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between Application.streamingAssetsPath and Application.persistentDataPath?How are they used?

I have doubt regarding certain concepts between these two. For Application.streamingAssetsPath, I should create a StreamingAssets folder in my project, so that I can save files to it and later reload it. So what is the role of Application.persistentDataPath and the role of Application.streamingAssetsPath?

If I have assets and data (Position, health etc) to be saved and later reload them in mobile devices (Android and IOS) and PC. Which is the best option?

Below I save using Application.streamingAssetsPath

using (FileStream fs = new FileStream(Application.streamingAssetsPath + "/Position.json", FileMode.Create))
    {
        BinaryWriter filewriter = new BinaryWriter(fs);
        filewriter.Write(JsonString);
        fs.Close();


    }
like image 453
zyonneo Avatar asked Sep 05 '25 19:09

zyonneo


1 Answers

Generally, use Application.persistentDataPath for data that was not available during build time and will be modified after being distributed (and should never be modified by a game update), and use Application.streamingAssetsPath for game data that exists before your build that you want to be able to read with IO systems during the game (and might be modified in a game update). For example, player save data likely should be placed in Application.persistentDataPath and dialogue files might be placed in Application.streamingAssetsPath.

The biggest technical difference is that usually Application.persistentDataPath can be saved in a location separate from the game data, so that an uninstall or update of the game will not cause a player to lose their data. Most of the difference is in intent, in that Application.persistentDataPath is intended for saving data between runs of a game, and Application.streamingAssetsPath is intended to allow developers to have game files that can be accessed by path name.


If you are storing the current position, current health, and current status of a character that you are keeping track of, you will want Application.persistentDataPath. If you are storing the data for the starting position, maximum health, and other stats of a character that you will use for initialization, Application.streamingAssetsPath would be a better pick.

like image 109
adisib Avatar answered Sep 08 '25 10:09

adisib