Saving Variable without Dont Destroy On Load

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
wlchfl5359
Posts: 29
Joined: Sat Jan 02, 2021 4:27 pm

Saving Variable without Dont Destroy On Load

Post by wlchfl5359 »

Hi, i want to save Dialogue Variable without Dont Destroy On Load. is it possible?

If i add component 'Save System', i can save Variable, but it says Dialogue Manager will be 'Dont Destroy On Load'.

Is there any different way to save Variable without that??
Thank you.
User avatar
Tony Li
Posts: 22161
Joined: Thu Jul 18, 2013 1:27 pm

Re: Saving Variable without Dont Destroy On Load

Post by Tony Li »

Hi,

Yes, there are two ways:

1. Put the Save System component on a different GameObject. That GameObject will be Dont Destroy On Load. Add a Dialogue System Saver component to the Dialogue Manager.

2. Or call PersistentDataManager.GetSaveData(). This will return a string containing the current variable values. To restore those values back into the Dialogue System, pass them to PersistentDataManager.ApplySaveData().
wlchfl5359
Posts: 29
Joined: Sat Jan 02, 2021 4:27 pm

Re: Saving Variable without Dont Destroy On Load

Post by wlchfl5359 »

Thank you for reply.

I tried a way No.1 but it doesn't save variable.

I created new object and put Save System component, and i put Dialogue System Saver component to Dialogue Manager Object. But it didn't save any variable :(
User avatar
Tony Li
Posts: 22161
Joined: Thu Jul 18, 2013 1:27 pm

Re: Saving Variable without Dont Destroy On Load

Post by Tony Li »

From your other thread, it sounds like maybe you are now using the default setting: Don't Destroy On Load. If so, that's the easiest way to make variable values stay the same across scene changes.

Otherwise, if you use a Save System GameObject, you must change scenes using one of these techniques.
wlchfl5359
Posts: 29
Joined: Sat Jan 02, 2021 4:27 pm

Re: Saving Variable without Dont Destroy On Load

Post by wlchfl5359 »

I'm using different asset to change scene.
So Should i use the way No.2 'using code : PersistentDataManager.ApplySaveData().'?
Thank you for reply.
User avatar
Tony Li
Posts: 22161
Joined: Thu Jul 18, 2013 1:27 pm

Re: Saving Variable without Dont Destroy On Load

Post by Tony Li »

Yes, you can either use PersistentDataManager.SaveGameData() before leaving the old scene and ApplyGameData() after entering the new scene.

Or, if you want to use the full save system, call these lines before leaving the old scene:

Code: Select all

PixelCrushers.SaveSystem.RecordSavedGameData();
PixelCrushers.SaveSystem.BeforeSceneChange();
and call this line after entering the new scene:

Code: Select all

PixelCrushers.SaveSystem.ApplySavedGameData();
Post Reply