Page 1 of 1

Gameobject status not saving across scene change

Posted: Sat Jan 18, 2020 5:42 pm
by chrislow19
Hi Tony, another question - sorry.

I use the dialogue system trigger to open a door (setting it to false and setting the gameobject inactive) that i walk through that takes me into the next scene. When I come back out, the door is reset to it's initial gameobject "true" setting. This is what I want for this particular object.

However, I have a piece of dialogue sequence I'm using to SetActive(NPC, True) an NPC gameobject somewhere else in the scene. If I set the game object to true, it reverts to false after a scene change. How can I get it to remain true during scene transitions?

Re: Gameobject status not saving across scene change

Posted: Sat Jan 18, 2020 7:52 pm
by Tony Li
Hi,

The values in your dialogue database (quest states, variables) will survive scene changes, assuming you haven't unticked the Dialogue Manager's Don't Destroy On Load checkbox.

To save other states, you can use the Dialogue System's save system and change scenes using one of these techniques:
  • The LoadLevel() sequencer command.
  • In code with SaveSystem.LoadScene().
  • The equivalent visual scripting action (e.g., the PlayMaker integration's Dialogue Sysmte > Load Scene action).
  • Add a SaveSystemMethods component to a GameObject and hook up a UnityEvent to call SaveSystemMethods.LoadScene.
If you can't use any of those techniques to change scenes, make sure to call SaveSystem.BeforeSceneChange before changing scenes some other way, and then call SaveSystem.ApplySavedGameData after loading the new scene.

Then add an ActiveSaver component to an active GameObject in the scene. It can be an empty GameObject. Assign the NPC to its GameObject To Watch field, and tick Save Across Scene Changes. The ActiveSaver will record the active/inactive state of the NPC in saved games and when leaving and returning to the scene.

BTW, to save the dialogue database values in saved games (and not just across scene changes in the same play session), add a DialogueSystemSaver component to the Dialogue Manager. (See DemoScene1 for an example of a Dialogue Manager GameObject with all of the save system components already set up.)

Re: Gameobject status not saving across scene change

Posted: Sat Jan 18, 2020 9:11 pm
by chrislow19
Hey there, I had most of that covered. The ActiveSaver component was the key! Thanks a ton! Is there some way to add gameobjects to the list besides setting up one for each object you want to save the status of?

Re: Gameobject status not saving across scene change

Posted: Sun Jan 19, 2020 8:57 am
by Tony Li
Hi,

Currently it's one GameObject per ActiveSaver. I'll add an ActiveMultiSaver component in the next update that lets you assign any number of GameObjects to watch.