Page 1 of 1
Questions about variables saving & scene changing
Posted: Sun Dec 17, 2023 10:26 am
by Lucian1899
Hi! Thank you for your patience in previous questions, sadly...here I am again.
I'm making a 2D AVG with this nice tool, and I have some questions about variables saving & scene changing.
1. I put Dialogue Manager in every sence, and I untick the "Don't Destory On Load", I wonder if it will affect data saving?
2. I am confused about saving system. I have already put variables and quest states in Initial Database, but they can't work in new scene. In my game, scene changing is only via button clicking, here is my loadscene script:
Code: Select all
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using PixelCrushers.DialogueSystem;
public class ChangeScene : MonoBehaviour
{
public string targetSceneName = "SceneB";
public void OnButtonClick()
{
PixelCrushers.SaveSystem.LoadScene("SceneB");
}
Really sorry for lacking coding knowledge, could you please tell me if my script is correct? Did I miss any methods? And what saving component should I use in each scene? Thank you so much!
Re: Questions about variables saving & scene changing
Posted: Sun Dec 17, 2023 10:40 am
by Tony Li
Hi,
Why did you untick Don't Destroy On Load?
In any case, make sure to set up the
Save System. This includes adding a Dialogue System Saver component, which will save variables when changing scenes. (Remember to assign a unique key to the Dialogue System Saver.)
Re: Questions about variables saving & scene changing
Posted: Sat Dec 23, 2023 8:16 am
by Lucian1899
Hi,
Why did you untick Don't Destroy On Load?
Because I made some mistakes in hierarchy or UI at that time...anyway, I can save variables and quest states now, but here is a new question: I couldn't save the old scene when I return to it.
In the manuel, I found that
The state is saved in memory, in the property SaveSystem.currentSavedGameData. After loading a scene, the save system will apply that scene's saver data from the in-memory SaveSystem.currentSavedGameData.
and
In C#, call SaveSystem.BeforeSceneChange() and SaveSystem.RecordSavedGameData() before changing scenes and SaveSystem.ApplySavedGameData() after changing scenes if you're using some other method to change scenes.
But I am really confused about it, could you please tell me how can I fix my scene changing script above and how to use the property? And my script reported a new error:
NotImplementedException: The method or operation is not implemented.
PixelCrushers.SaveSystem.LoadScene (System.String sceneNameAndSpawnpoint) (at Assets/Plugins/Pixel Crushers/Common/Scripts/Save System/SaveSystem.cs:863)
I'm not sure where I did wrong, sorry for my coding knowledge.Thank you so much!
Re: Questions about variables saving & scene changing
Posted: Sat Dec 23, 2023 8:59 am
by Tony Li
Hi,
I recommend setting up the save system:
Save System Setup.
Then use the save system to change scenes:
Changing Scenes.
Re: Questions about variables saving & scene changing
Posted: Sat Dec 23, 2023 10:12 am
by Lucian1899
Hi,
Thanks, I think I have set up the save system.
As for Changing Scenes, the manual lists 5 techniques and I'm not sure I should use the first or second? And does scene changing script belongs to "some other method to change scenes" that mentioned in technique 2? Really appreciate your patience.
Re: Questions about variables saving & scene changing
Posted: Sat Dec 23, 2023 10:28 am
by Tony Li
Hi,
The 5 different options all do the same thing. The Dialogue System provides the different options to give you flexibility in what you want to do.
If you want to change scenes while a conversation is playing, I recommend using the LoadLevel() sequencer command.
The second option (SaveSystem.BeforeSceneChange(), SaveSystem.RecordSavedGameData(), etc.) is only for when you're using a different method to change scenes, such as a third party scene-changing asset. In cases like this, it's sometimes not possible to use SaveSystem.LoadScene or the LoadLevel() sequencer command because the third party asset isn't flexible enough.
Re: Questions about variables saving & scene changing
Posted: Wed Jan 17, 2024 8:56 am
by Lucian1899
Hi,
Thanks Tony, the first option worked, and I found my mistake...actually, I forgot to add Active saver component to some gameobjects, so I thought I didn't save the old scene. Thank you for your patience again.
Re: Questions about variables saving & scene changing
Posted: Wed Jan 17, 2024 9:20 am
by Tony Li
Happy to help! I'm glad you found the issue.