Accessing persistent data without running the game

Announcements, support questions, and discussion for the Dialogue System.
fkkcloud
Posts: 298
Joined: Mon Oct 05, 2020 6:00 am

Accessing persistent data without running the game

Post by fkkcloud »

Hello,

Is it possible to access persistent data without running the game?

For instance, I want to save/load states while in Editor without playing the session.

Code: Select all

saveObject.dialogueSystemSave = PixelCrushers.DialogueSystem.PersistentDataManager.GetSaveData();

Code: Select all

PixelCrushers.DialogueSystem.PersistentDataManager.ApplySaveData( saveData.dialogueSystemSave );
Also, where can I manually set/see the persistent data?

Thank you
User avatar
Tony Li
Posts: 22051
Joined: Thu Jul 18, 2013 1:27 pm

Re: Accessing persistent data without running the game

Post by Tony Li »

Hi,

Are you using the Dialogue System's save system? If so, then it depends on which saved game data storer you're using. Here's an example of using PlayerPrefsSavedGameDataStorer and JsonDataSerializer:

Code: Select all

var storer = FindObjectOfType<PlayerPrefsSavedGameDataStorer>();
var playerPrefsKey = storer.GetPlayerPrefsKey(slotNumber);
var rawData = PlayerPrefs.GetString(playerPrefsKey);
var savedGameData = JsonUtility.FromJson<SavedGameData>(rawData);

Debug.Log("Game was saved in scene: " + savedGameData.sceneName);

var rawPositionData = savedGameData.GetData("PlayerPosition");
var positionData = JsonUtility.FromJson<PositionSaver.PositionData>(rawPositionData);
Debug.Log("Player position: " + positionData.position);

If you're not using the save system, and if you're only using PersistentDataManager.GetSaveData(), then this function only returns a string. It's up to you to do something with the string. The string is Lua code, so you can print it out to see what it contains. Or you can create a Lua object at runtime and run it through that.
fkkcloud
Posts: 298
Joined: Mon Oct 05, 2020 6:00 am

Re: Accessing persistent data without running the game

Post by fkkcloud »

Hello,

Yes, I am not using Save System. The part I am asking is...
If I call this function in Editor (while not playing)

Code: Select all

PixelCrushers.DialogueSystem.PersistentDataManager.GetSaveData();
It throws an error.
화면 캡처 2021-01-15 094738.png
화면 캡처 2021-01-15 094738.png (88.03 KiB) Viewed 631 times
If I run the code while playing it does not.
I just want to call these 2 functions without playing the session.

Code: Select all

PixelCrushers.DialogueSystem.PersistentDataManager.GetSaveData();

Code: Select all

PixelCrushers.DialogueSystem.PersistentDataManager.ApplySaveData( saveData.dialogueSystemSave );
User avatar
Tony Li
Posts: 22051
Joined: Thu Jul 18, 2013 1:27 pm

Re: Accessing persistent data without running the game

Post by Tony Li »

Hi,

If the game isn't running, then there is no save data to get. So PersistentDataManager.GetSaveData() won't work.

What do you want to accomplish?
fkkcloud
Posts: 298
Joined: Mon Oct 05, 2020 6:00 am

Re: Accessing persistent data without running the game

Post by fkkcloud »

I want to go into save state A from B sometimes just for debug purposes.

Like switching datasets in Scriptable Objects
User avatar
Tony Li
Posts: 22051
Joined: Thu Jul 18, 2013 1:27 pm

Re: Accessing persistent data without running the game

Post by Tony Li »

What if you use PersistentDataManager.GetSaveData() during play to record a state. Then save this string somewhere, such as in EditorPrefs or PlayerPrefs.

Add another script that can retrieve this string and apply it using PersistentDataManager.ApplySaveData() during play.
fkkcloud
Posts: 298
Joined: Mon Oct 05, 2020 6:00 am

Re: Accessing persistent data without running the game

Post by fkkcloud »

Maybe I should do that.

Besides that, if I want to set some value manually- where do I want to go?
User avatar
Tony Li
Posts: 22051
Joined: Thu Jul 18, 2013 1:27 pm

Re: Accessing persistent data without running the game

Post by Tony Li »

Here are ways to set a Lua value manually:
  • Use the "Run" field at the bottom of the Dialogue Editor's Watches panel.
  • Add a Lua Console to your scene. Press ~+L to open it during play. Then enter Lua code. To view a value, use "return". Example:

    Code: Select all

    Variable["x"] = 42
    return Variable["x"]
    Unlike the Dialogue Editor window, you can use a Lua Console in a build. You can also register your own C# methods as Lua functions and call them in the Lua Console.
  • In a C# script, use DialogueLua.SetVariable:

    Code: Select all

    DialogueLua.SetVariable("x", 42);
fkkcloud
Posts: 298
Joined: Mon Oct 05, 2020 6:00 am

Re: Accessing persistent data without running the game

Post by fkkcloud »

Oh thank you,

and is there any UI as well?
like seeing the list of data in one place? and edit them there? (while not running the game)
User avatar
Tony Li
Posts: 22051
Joined: Thu Jul 18, 2013 1:27 pm

Re: Accessing persistent data without running the game

Post by Tony Li »

The save data is Lua code. You can look at it in a text editor. It will look similar to:

Code: Select all

Variable = { Alert = "", x = 42 }; Actor["Player"] = { Name = "Player", IsPlayer = true } ...
Post Reply