Best Practice on working with VCS / persistentDataPath

Easy Save 2 has been replaced by Easy Save 3, so is no longer supported.
Locked
actraiser
Posts: 12
Joined: Tue Apr 28, 2015 9:50 am

Best Practice on working with VCS / persistentDataPath

Post by actraiser »

Hello,

I am new to Unity and Easy Save, so maybe the following solution for the following problem is obvious but I have not found it yet.

I use Easy Save 2 to store my Level Designs (Position of placed Objects in the particular Level etc one file per level). I now run into the problem that I want to store the level-files within the project's resource folder so they can be submitted to my Git-Repository. As I noticed, with a custom path configured in the Easy Save-Settings, Application.persistentDataPath is not used and the Levels do not show up on mobile devices as files can not be loaded.

What is best practice to make sure the level files are available in Application.persistentDataPath as well as in my configured custom path so the data is versioned? I guess I could simply save the file twice when saving a created level but maybe there is a smarter way. Alternatively, is there a possibility to step into the building process like, say, to copy files from the custom path to the Application.persistentDataPath when I create iOS/Android builds?

Thanks for any advice.

Greets
-act
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Best Practice on working with VCS / persistentDataPath

Post by Joel »

Hi there,

If you only need to save when running in the Editor and don't need to save to the files after the app has been built, you can simply save and load from Resources using the instructions here.

If you need to save to the files after the application has been built, the best thing to do would be to save to Resources as above so that the files are included with the build, but then when the app first loads up, move the data from Resources to Application.persistentDataPath. The easiest way to do this would be using ES2.LoadRaw and ES2.SaveRaw, like this:
public void MoveFileFromResourcesToPDP(string filename)
{
    // If this file hasn't already been moved from Resources to persistentDataPath, move it.
    if(!ES2.Exists(filename))
        ES2.SaveRaw(filename, ES2.LoadRaw(filename+"?savelocation=resources") );
}
All the best,
Joel
actraiser
Posts: 12
Joined: Tue Apr 28, 2015 9:50 am

Re: Best Practice on working with VCS / persistentDataPath

Post by actraiser »

Awesome - this worked! Thank you very much! Only one extra question, can I specify a custom sub-folder within the Resources-Location, e.g. /Resources/Levelconfig/ ?

Just adding the string to the settings.saveLocation results into "Cannot implicitly convert type `string' to `ES2Settings.SaveLocation'"

Code: Select all

settings.saveLocation = ES2Settings.SaveLocation.Resources + "LevelConfig/Levels/";  // does not work 
Thanks again.
-act
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Best Practice on working with VCS / persistentDataPath

Post by Joel »

Hi again,

To load from a subfolder within resources, you need to add the folder to the beginning of the filepath. i.e. if we were loading an int from a subfolder in Resources, we'd do this:
ES2Settings settings = new ES2Settings();
settings.saveLocation = ES2Settings.SaveLocation.Resources;

int myInt = ES2.Load<int>("Levelconfig/myFile.txt?", settings);
All the best,
Joel
actraiser
Posts: 12
Joined: Tue Apr 28, 2015 9:50 am

Re: Best Practice on working with VCS / persistentDataPath

Post by actraiser »

Thank You Joel!

-act
Locked