Page 1 of 1

Saving only quests and variables

Posted: Thu Jul 06, 2023 3:00 am
by Maltakreuz
I am implementing save / load in my game. As I have my own system, I only want to save/load dialogue database. That's works fine with

Code: Select all

string dialogueSysSaveData = PersistentDataManager.GetSaveData();
But after I have inspected what will be actually saved, I see a lot redundant and unnecessary (in my opinion) savedata. Most space will be used just to save Actors, including all language translations like this:
Actor={Lionessy={Name=\"Lionessy\", Pictures=\"[]\", Description=\"\", IsPlayer=true, Name_ru=\"Львичка\", Name_de=\"Löwinlein\", Name_zh=\"母狮\"}, Alchemist={Name=\"Alchemist\", Pictures=\"[]\", Description=\"old killme\", IsPlayer=false, Name_ru=\"Алхимик\", Name_de=\"Alchemist\", Name_zh=\"Alchemist\"}, [\"Шахтёр_Лорн\"]={Name=\"Шахтёр Лорн\", Pictures=\"[]\", Description=\"\", IsPlayer=false, Name_ru=\"\", Name_de=\"\", Name_zh=\"\"}, Zuqaqip_the_Shepherd={Name=\"Zuqaqip the Shepherd\", Pictures=\"[]\", Description=\"\", IsPlayer=false, Name_ru=\"Пастух Зукакип\", Name_de=\"Hirte Zukakip\", Name_zh=\"牧羊人\"}, Didi_the_Rogue={Name=\"Didi the Rogue\", Pictures=\"[]\", Description=\"old killme\", IsPlayer=false, Name_ru=\"\", Name_de=\"\", Name_zh=\"\"}, Shushanna_the_Daggermaster={Name=\"Shushanna the Daggermaster\", Pictures=\"[]\", Description=\"old killme\", IsPlayer=false, Name_ru=\"\", Name_de=\"\", Name_zh=\"\"}, Traveler={Name=\"Traveler\", Pictures=\"[]\", Description=\"First NPC when coming into savannah\", IsPlayer=false
1) I want to understand first, why actors and translations will be saved at all? All NPC names and their translations are just permanent data and will not ever change. So I do not see any point to save them. Moreover, even if I will find some typo in name or translation, I for sure do not want it to be saved at all. So what is the point to save Actors at all? Including translations and even descriptions?

2) If it is realy unnecessary, can I somehow crop Actors from savefile?

Code: Select all

string dialogueSysSaveData = PersistentDataManager.GetSaveData();
Can this method be adjusted in that way?

3) Btw: Can I pretty print it?

Re: Saving only quests and variables

Posted: Thu Jul 06, 2023 7:29 am
by Maltakreuz
Ah, found it:

Code: Select all

PersistentDataManager.includeActorData
But still interested in which case this (normally static) data should be included and could it be used with prettyPrint like JsonUtility does?

Re: Saving only quests and variables

Posted: Thu Jul 06, 2023 8:51 am
by Tony Li
Hi,

There's no pretty print for PersistentDataManager.GetSaveData(), although you could put the code into a Lua formatter like this one to get a more readable version.

BTW, you can set PersistentDataManager.includeActorData false without any code. Inspect the Dialogue Manager GameObject's Persistent Data Settings section and UNtick Include Actor Data.

Re: Saving only quests and variables

Posted: Wed Aug 09, 2023 1:16 pm
by Maltakreuz
Well... I have found one case where it makes sense. If I set another portrait to NPC, it will be lost after load. Or I need to add some conditions in dialogue to make dialogues rely only on lua vars. But with PersistentDataManager.includeActorData = true current portrait will be also saved like this:
Current_Portrait=\"pic=2\"

Now, I am not sure if I want to enable it anyways. Pro: current portraits for NPCs. Con: all names will be stored, so if typo is there, it can not be fixed just by fixing it in game data, as it will be overwritten with value stored in save file.

Re: Saving only quests and variables

Posted: Wed Aug 09, 2023 2:44 pm
by Tony Li
Hi,

You could hook into the load game process and update Display Names. Something like:

Code: Select all

SaveSystem.saveDataApplied += OnSaveDataApplied;
SaveSystem.LoadFromSlot(1);
...
void OnSaveDataApplied()
{
    SaveSystem.saveDataApplied -= OnSaveDataApplied;
    foreach (var actor in DialogueManager.masterDatabase.actors)
    {
        DialogueLua.SetActorField(actor.Name, "Display Name", actor.LookupValue("Display Name"));
    }
}