Error when loading saveData

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
munkbusiness
Posts: 8
Joined: Wed Jun 14, 2023 10:33 am

Error when loading saveData

Post by munkbusiness »

Hi I have my own data saving system, that very simply saves data into a file to read it later. I have used this save system before in released games.

I implemented the save system for variables and quests for the dialogue system, but when I try to load it I get an error. Have I missudnerstood how to use it? It happens exactly when I do ApplySaveData.

My code:

Code: Select all

public void LoadSaveData() {
        saveData = SaveManager.LoadGameData(out bool wasEmpty);
        if(!wasEmpty) {
            PersistentDataManager.ApplySaveData(saveData.dialogueSystemData);
        }
    }

public void SaveGameData() {
        string s = PersistentDataManager.GetSaveData(); // Dialogue system data
        saveData.dialogueSystemData = s;

        SaveManager.SaveGameData(saveData);
}
When debugging I can see that the string I get looks like this:

Code: Select all

"Variable={Alert=\"\", GeoTrack=\"W1L1\", [\"function.LocalRNG\"]=0, [\"function.RangeRNG\"]=0, [\"function.Battlewon\"]=false, LimitedChars=true, [\"rundata.HasFoughtRichMerchant\"]=false, charTrack=\"Namechange error\", BTmusclememory=false, BTshrine=true, PlayerGold=0, PlayerHealth=0, PlayerLives=0, BToldman=false, BTFruitRed=false, BTFruitBlue=false, BTFruitYellow=false, BTrecruitNaras=false, BTrecruitDion=false, Locked_=true, PartyNumber=1, Actor=\"\", Conversant=\"\", ActorIndex=\"\", ConversantIndex=\"\"}; Item[\"WarriorLead\"].State=\"active\"; Item[\"DruidLead\"].State=\"unassigned\"; Actor={_PC_Warrior={Name=\"(PC)Warrior\", Pictures=\"[]\", Description=\"\", IsPlayer=true, NodeColor=\"#e2a536ff\", Display_Name=\"Dion\"}, _PC_Druid={Name=\"(PC)Druid\", Pictures=\"[]\", Description=\"\", IsPlayer=false, NodeColor=\"#d36094ff\", Display_Name=\"Naras\"}, Responsive={Name=\"Responsive\", Pictures=\"[]\", Description=\"Placeholder: When a node responsively should decide actor\", IsPlayer=true, NodeColor=\"#d8d7d7ff\", Display_Name=\"Namechange error\"}, [\"\"]={Name=\"\", Pictures=\"[]\", Description=\"The world actor (get info from world)\", IsPlayer=false, Display_Name=\"\", NodeColor=\"#fae1e1ff\"}, SHOP_Nomadic={Name=\"SHOP Nomadic\", Pictures=\"[]\", Description=\"\", IsPlayer=false, NodeColor=\"#77b2b9ff\", Display_Name=\"Nomadic Trader\"}, Old_man={Name=\"Old man\", Pictures=\"[]\", Description=\"Old man character\", IsPlayer=false, NodeColor=\"#77b2b9ff\"}, [\"????\"]={Name=\"????\", Pictures=\"[]\", Description=\"Gives direction in Phase 1.\", IsPlayer=false, NodeColor=\"#2d2d2dff\"}, _PC__Rogue={Name=\"(PC) Rogue\", Pictures=\"[]\", Description=\"As of yet not in use in the game (test)\", IsPlayer=true}, _PC__Sorcerer={Name=\"(PC) Sorcerer\", Pictures=\"[]\", Description=\"As of yet not in use in the game (test)\", IsPlayer=true}, _PC__Cleric={Name=\"(PC) Cleric\", Pictures=\"[]\", Description=\"As of yet not in use in the game (test)\", IsPlayer=true}, Bandit1={Name=\"Bandit1\", Pictures=\"[]\", Description=\"Bandit in bandit-toll\", IsPlayer=false, Display_Name=\"Toll Person.\", NodeColor=\"#77b2b9ff\"}, Robot_Robot_Surgeon={Name=\"Robot Robot Surgeon\", Pictures=\"[]\", Description=\"A rando who upgrades.\", IsPlayer=false, Display_Name=\"Robot Robot Surgeon.\", NodeColor=\"#77b2b9ff\"}, Gambling_host={Name=\"Gambling host\", Pictures=\"[]\", Description=\"The host of the house of wagers. \", IsPlayer=false, Display_Name=\"Hostess\", NodeColor=\"#77b2b9ff\"}, Stranger={Name=\"Stranger\", Pictures=\"[]\", Description=\"With a thing\", IsPlayer=false, NodeColor=\"#77b2b9ff\"}, Error_Actor={Name=\"Error Actor\", Pictures=\"[]\", Description=\"Error expression in character change\", IsPlayer=true, NodeColor=\"#bb8787ff\", Display_Name=\"Ch. Change Error.\"}, Strange_Voice={Name=\"Strange Voice\", Pictures=\"[]\", Description=\"The machine spirit/ Rogue Architecht.\", IsPlayer=false, NodeColor=\"#454545ff\", Display_Name=\"Strange Voice\"}}; StatusTable = \"\"; RelationshipTable = \"\"; "
The error:

Code: Select all

NullReferenceException: Object reference not set to an instance of an object
PixelCrushers.DialogueSystem.PersistentDataManager.EnsureQuestsExist (System.String saveData) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/Save System/PersistentDataManager.cs:351)
PixelCrushers.DialogueSystem.PersistentDataManager.ApplyLuaInternal (System.String saveData, System.Boolean allowExceptions) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/Save System/PersistentDataManager.cs:260)
PixelCrushers.DialogueSystem.PersistentDataManager.ApplySaveData (System.String saveData, PixelCrushers.DialogueSystem.DatabaseResetOptions databaseResetOptions) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/Save System/PersistentDataManager.cs:246)
PlayerData.LoadSaveData () (at Assets/Scripts/PlayerData.cs:66)
User avatar
Tony Li
Posts: 21678
Joined: Thu Jul 18, 2013 1:27 pm

Re: Error when loading saveData

Post by Tony Li »

Hi,

Does your scene have a Dialogue Manager GameObject?

If so, are you running your code in Start() or later, not Awake(), to give the Dialogue Manager a chance to initialize itself?
munkbusiness
Posts: 8
Joined: Wed Jun 14, 2023 10:33 am

Re: Error when loading saveData

Post by munkbusiness »

Oh that might be the issue, I am running the loading in awake, in the same scene as I have my "Dialogue system controller" object.

If my loading cannot happen in awake I have to change a few other things before I can test if it is enough to move the loading to start.
munkbusiness
Posts: 8
Joined: Wed Jun 14, 2023 10:33 am

Re: Error when loading saveData

Post by munkbusiness »

Moving to start did the job, thank you so much for the quick response.
User avatar
Tony Li
Posts: 21678
Joined: Thu Jul 18, 2013 1:27 pm

Re: Error when loading saveData

Post by Tony Li »

Glad to help!
Post Reply