Scene to scene transitioning

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
simplepleasuresdxy
Posts: 73
Joined: Tue Jul 25, 2023 1:34 am

Scene to scene transitioning

Post by simplepleasuresdxy »

Hi there,


I wanted to ask how i could save things like variables and the like from scene to scene. If i move to a new scene i dont want to lose a boolean turning back to false for example.

The documentation hasnt helped me here so i dont know what to do.
User avatar
Tony Li
Posts: 21681
Joined: Thu Jul 18, 2013 1:27 pm

Re: Scene to scene transitioning

Post by Tony Li »

Hi,

Use the Save System.
  • At the top of that Save System link, there's a screenshot of the Dialogue Manager GameObject. Add the components shown in the screenshot to your Dialogue Manager.
  • Change scenes using any of these techniques.
  • Add "Saver" components such as ActiveSaver (saves a GameObject's active/inactive state) and PositionSaver (saves a GameObject's position) to objects in your scene.
  • If you need to data in your own scripts that aren't covered by any of the built-in Saver components, please see: How To: Write Custom Savers
simplepleasuresdxy
Posts: 73
Joined: Tue Jul 25, 2023 1:34 am

Re: Scene to scene transitioning

Post by simplepleasuresdxy »

So .... im confused how this works. When i put this save system in, do i still have to have dialogue manager in that other scene with its own variable for variables? What about for that magic power i was talking to you about? I have a data container game object that saves the variable in unity


Does the saver component only affect dialogue manager stuff or does it also have to affect things in unity i already have their own saver systems for? (Like i already have code that is remember between scenes)
User avatar
Tony Li
Posts: 21681
Joined: Thu Jul 18, 2013 1:27 pm

Re: Scene to scene transitioning

Post by Tony Li »

Hi,

At runtime, the Dialogue Manager GameObject survives scene changes and replaces any Dialogue Managers that are present in subsequently-loaded scenes. This means you can put a Dialogue Manager GameObject in every scene to make it easy to playtest that scene directly in the Unity editor's play mode. Or you can put a Dialogue Manager only in the first scene if you prefer.

The saver components only affect the Dialogue Manager stuff and anything that you've specifically set up a Saver component for, such as a PositionSaver on some GameObject. It won't get in the way of your other, non-Dialogue System save code. However, in order for the Dialogue System save stuff to work, you do need to change scenes using one of the methods I linked above. For example, if you have a script that changes scenes using this code:

Code: Select all

SceneManager.LoadScene("Some Scene Name");
then you can change it to:

Code: Select all

PixelCrushers.SaveSystem.LoadScene("Some Scene Name");
simplepleasuresdxy
Posts: 73
Joined: Tue Jul 25, 2023 1:34 am

Re: Scene to scene transitioning

Post by simplepleasuresdxy »

So ... if it replaces itnin the next scene, what will happen to the dialogue written for the scene? What does the saver actually do then? Im very confused
User avatar
Tony Li
Posts: 21681
Joined: Thu Jul 18, 2013 1:27 pm

Re: Scene to scene transitioning

Post by Tony Li »

Hi,

Put all of your dialogue in a single dialogue database. Assign that dialogue databases to the Dialogue Manager GameObjects in all of your scenes. (If you only have one Dialogue Manager GameObject in your starting scene, then just assign it there.)

When you change scenes, the Dialogue Manager -- and the dialogue database assigned to it -- will survive the scene change. So your dialogue will still be available in the newly-loaded scene.

Here's how the save system works:
  • The Save System component has memory.
  • When you use one of the techniques above to change scenes, the Save System asks all of the Saver components in the current scene to record their states. Then the Save System component stores those states in its memory. A Position Saver component will record the position of its GameObject. The Dialogue System Saver component, which is one of the components you will have added to the Dialogue Manager GameObject, records the values of all dialogue database variables and quest states.
  • Then the Save System changes scenes to the new scene.
  • In the new scene, the Save System asks all Saver components in the new scene to restore their saved states from the Save System's memory. This includes the Dialogue System Saver, which restores the dialogue database variable values and quest states.
simplepleasuresdxy
Posts: 73
Joined: Tue Jul 25, 2023 1:34 am

Re: Scene to scene transitioning

Post by simplepleasuresdxy »

okay, thank you.

Hopefully the other questions on my other posts will be as easy to answer as this one. Thank you
Post Reply