Page 2 of 2
Re: Saving issue
Posted: Thu Dec 16, 2021 1:21 pm
by Tony Li
Hi,
Yes. Let's say you're keeping track of the most recently-saved slot number in a variable named mostRecentSlotNumber, and your character customization is in a Saver script named CharacterCustomizationSaver saved under the key "customization". To load save data without applying it.
Code: Select all
using PixelCrushers;
...
SavedGameData savedGameData = SaveSystem.storer.RetrieveSavedGameData(mostRecentSlotNumber);
string s = savedGameData.GetData("customization");
CharacterCustomizationData characterCustomizationData = SaveSystem.Deserialize<CharacterCustomizationData>(s);
Re: Saving issue
Posted: Thu Dec 16, 2021 1:54 pm
by SealDev
Awesome! How about retriving just a variable value from that slot?
Re: Saving issue
Posted: Thu Dec 16, 2021 2:21 pm
by Tony Li
If you're talking about a variable in your CharacterCustomizationData, like this:
Code: Select all
...
CharacterCustomizationData characterCustomizationData = SaveSystem.Deserialize<CharacterCustomizationData>(s);
string weaponName = characterCustomizationData.weaponName;
If you're talking about a Dialogue System variable, since you're in the main menu you can just apply it to the Dialogue System since the data will be reset when you actually load a saved game. Example:
Code: Select all
using PixelCrushers.DialogueSystem;
...
string s = savedGameData.GetData("ds"); // Assumes your DialogueSystemSaver's Key is "ds".
PersistentDataManager.ApplySaveData(s);
string myVariableValue = DialogueLua.GetVariable("My Variable");
Re: Saving issue
Posted: Fri Dec 17, 2021 7:06 am
by SealDev
I tried for a couple of hours but couldn't get it to retrieve data!
It debugs 0, the default variable value of "CurrentHat" not just OnSaveDataApplied, but also on update.
My game only uses save slot 0. Don't know why but data is not applying. I also made sure to give the DialogueSystemSaver the key "ds", still won't load.
Re: Saving issue
Posted: Fri Dec 17, 2021 8:57 am
by Tony Li
Hi,
Try breaking it down to make sure we're getting the correct data from the saved game
Code: Select all
string s = SaveSystem.storer.RetrieveSavedGameData(0).GetData("ds");
Debug.Log("Saved DS data: " + s);
PersistentDataManager.ApplySaveData(s);
...
Re: Saving issue
Posted: Fri Dec 17, 2021 1:48 pm
by SealDev
Using exactly your code, it outputs nothing (1.png)
And yes, I do already have a save file, with a different hat equipped (2.png). It's just that it only loads on Play
Pic of dialogue manager object (3.png / 3b.png)
Re: Saving issue
Posted: Fri Dec 17, 2021 2:33 pm
by Tony Li
The key is different since you've ticked the DialogueSystemSaver's Append Saver Type To Key. Options:
1. UNtick Append Saver Type To Key. Re-save the game so the data is saved under "ds".
2. Or use "ds_DialogueSystemSaver" for the key.
Re: Saving issue
Posted: Fri Dec 17, 2021 3:16 pm
by SealDev
Thank you so much
Final question! In general, when running string operations, is performance worse with longer words than shorter ones?
Re: Saving issue
Posted: Fri Dec 17, 2021 3:32 pm
by Tony Li
In general, the performance difference in length in negligible.
You do you want to avoid manipulating strings -- such as concatenating them like this:
because it generates garbage memory that will need to be garbage-collected at some point. If you're doing it every once in a while, it's fine. Just don't do it every frame, such as in Update().