Shipping Savegames files with apk

Discussion and help for Easy Save 3
Post Reply
kiabws
Posts: 3
Joined: Thu Jul 08, 2021 7:21 pm

Shipping Savegames files with apk

Post by kiabws »

Hey,
I'm pretty new to ES3 so I hope there is an solution for my problem :)
I've made an android game where you can save and load multiple savegames on runtime, meaning you create a new .es3 file in a "Persistent Data Path". Now I want to actually add some already existing savegames for the player, meaning I (as a developer) create the .es3 file and ship it within the apk.
My first approach was to use a (not persistent?) "Data Path" and just drop them somewhere in the Assets Folder, with the following code I can check if my system finds the file:

Code: Select all

        foreach (string potentialES3File in ES3.GetFiles("More/SaveGames"))
        {
            Debug.Log(potentialES3File);
        }
In the Editor and on a windows build I get my es3 files printed/logged, but as I expected on Android it's not working because there is no "data path" on android, right? So my question is, if there is another solution for my problem or another approach to ship .es3 files with my apk.
User avatar
Joel
Moodkie Staff
Posts: 4852
Joined: Wed Nov 07, 2012 10:32 pm

Re: Shipping Savegames files with apk

Post by Joel »

Hi there,

If you want files to be included with the build you will need to add them to the Resources folder (see https://learn.unity.com/tutorial/assets ... setbundles).

There's information on loading from the resources folder using Easy Save here:
https://docs.moodkie.com/easy-save-3/es ... resources/

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
kiabws
Posts: 3
Joined: Thu Jul 08, 2021 7:21 pm

Re: Shipping Savegames files with apk

Post by kiabws »

Thanks for the quick response. I was able to save my first file as a ".byte". Is it possible to Cache the Resource or somehow "translate" it back and save it to the "data path" as an .es3 file?
User avatar
Joel
Moodkie Staff
Posts: 4852
Joined: Wed Nov 07, 2012 10:32 pm

Re: Shipping Savegames files with apk

Post by Joel »

Hi there,

You can use the ES3.MoveFile method, ensuring that the save location is set to Resources for the oldSettings parameter, and set to File for the newSettings parameter:

https://docs.moodkie.com/easy-save-3/es ... -copyfile/

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
kiabws
Posts: 3
Joined: Thu Jul 08, 2021 7:21 pm

Re: Shipping Savegames files with apk

Post by kiabws »

I don't have a ES3.MoveFile() function, but I'm sure you meant ES3.CopyFile(). I tried using it but overall I think my .byte file is simply not correct, because using the function did pretty much nothing, not even a log entry or warning/error.
In the documentation it says
Alternatively, you can save data to a folder of your choice and then drag it into the Resources folder.

Code: Select all

 ES3.Save<int>("myKey", 123, Application.dataPath+"/Resources/myFile.bytes");
AssetDatabase.Refresh();
should this file be saved with the location setting "ES3.Location.File" or "ES3.Location.Resources"? I can only save it with the "file" location and I'm not sure if changing the ending from .es3 to .byte is all I have to do.
I did a small test.es3/test.byte and both files look like this:

Code: Select all

	"missionID" : {
		"__type" : "int",
		"value" : -1
	},
	"mapID" : {
		"__type" : "int",
		"value" : 1
	},
	"saveGameName" : {
		"__type" : "string",
		"value" : "asdasda"
	},
	"dateTime" : {
		"__type" : "System.DateTime,mscorlib",
		"value" : {
			"ticks" : 637613808181905035
		}
	}
loading with ES3.GetFiles() and Es3.KeyExist() works fine with when loading from the file, but with the following code I get the error "FileNotFoundException: File "asdasda-meta" could not be found.
ES3.Load[T] (System.String key, ES3Settings settings) (at Assets/Plugins/Easy Save 3/Scripts/ES3.cs:394)
ES3.Load[T] (System.String key, System.String filePath, ES3Settings settings) (at Assets/Plugins/Easy Save 3/Scripts/ES3.cs:379)
"

Code: Select all

        ES3Settings loadFromResource = ES3Settings.defaultSettings;
        loadFromResource.location = ES3.Location.Resources;
        AssetDatabase.Refresh();
        var myMissionID = ES3.Load<int>("missionID", "asdasda-meta.bytes", loadFromResource);
        Debug.Log(myMissionID);
User avatar
Joel
Moodkie Staff
Posts: 4852
Joined: Wed Nov 07, 2012 10:32 pm

Re: Shipping Savegames files with apk

Post by Joel »

Hi there,
I don't have a ES3.MoveFile() function, but I'm sure you meant ES3.CopyFile().
Apologies, CopyFile is correct.
I tried using it but overall I think my .byte file is simply not correct, because using the function did pretty much nothing, not even a log entry or warning/error.
Please could you show me the code you are using? Including the code you're using to demonstrate that the file wasn't copied.
should this file be saved with the location setting "ES3.Location.File" or "ES3.Location.Resources"?
It needs to be saved to the File save location because Resources is not writable at runtime.
I did a small test.es3/test.byte and both files look like this
Changing the extension will not change the format of the file, and you don't need to change the format of the file. You need to provide .bytes as the file extension as Unity requires this.
loading with ES3.GetFiles() and Es3.KeyExist() works fine with when loading from the file, but with the following code
Are you exiting playmode between saving and loading? This is necessary because any changes you make to Resources won't be applied until you exit playmode. Please see Unity's documentation on Resources for more information.

If this isn't the issue, please could you show me the code you're using to save the data to Resources?

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Post Reply