I was having some issues setting up the Save system to work between scenes. I was wondering if you had an example project like you do for a couple other systems?
The setup I have now is that I have a dialogue manager in each scene. I'm trying to set up a "Skip Intro" button that sets a bool to true and that persists between the scenes.
The issue is that in the main menu screen, the trigger is true and the object persists through the scene change but when I open the main scene the bool does not change. I checked in watches and it still shows as false when the scene loads.
DemoScene1 and DemoScene2 demonstrate saving data across scene changes.
At runtime, the Dialogue Manager MainMenuScene will survive scene changes and replace the Dialogue Manager that was in MainScene at design time. (Unless you've intentionally unticked its Don't Destroy On Load and Only Allow One Instance checkboxes.) Even without using the save system, since the Dialogue Manager survives scene changes the variable value should persist across scene changes.
If you're entering play mode directly in MainScene instead of coming from MainMenuScene, you'll need to load the DS variables and other save data from a saved game.
Also, how are you changing scenes? Are you using any of the methods described here? It shouldn't matter for DS variables (assuming the Dialogue Manager is still configured to survive scene changes), but it will matter for other Saver components.
DemoScene1 and DemoScene2 demonstrate saving data across scene changes.
At runtime, the Dialogue Manager MainMenuScene will survive scene changes and replace the Dialogue Manager that was in MainScene at design time. (Unless you've intentionally unticked its Don't Destroy On Load and Only Allow One Instance checkboxes.) Even without using the save system, since the Dialogue Manager survives scene changes the variable value should persist across scene changes.
If you're entering play mode directly in MainScene instead of coming from MainMenuScene, you'll need to load the DS variables and other save data from a saved game.
Also, how are you changing scenes? Are you using any of the methods described here? It shouldn't matter for DS variables (assuming the Dialogue Manager is still configured to survive scene changes), but it will matter for other Saver components.
Hey Tony, first I have a splash screen that I enter in play mode that has a continue button and loads MainMenuScene. That one works correctly, it's setup with a Dialogue System Trigger using the sequence "LoadLevel(MainMenuScene);".
In MainMenuScene I have two buttons, one that leads to the intro cinematic using the same method and the other that is supposed to skip the intro and also skip the tutorial that automatically starts on loading MainScene.
I plan on having a couple different dialogue layouts depending on the scene, and I also use it for the intro cinematic, so I figured that was the way to do it.
So in this case, I should decouple the UI from the Dialogue Manager and just have the Dialogue Manager as the object to survive scene changes?
Although by no means required, it'll probably be much easier in the long run to allow the Dialogue Manager to survive scene changes. Assign a default dialogue UI to the Dialogue Manager. Then use Override Dialogue UI and/or Override Display Settings components to use different UIs for different purposes. You can also change the dialogue UI for a whole scene by adding a script with a Start() method to the scene, such as:
public class SetDialogueUIForScene : MonoBehaviour
{
public GameObject dialogueUI; // Assign in inspector.
void Start()
{
DialogueManager.UseDialogueUI(dialogueUI);
}
}
Thanks Tony, I think I'll do that. I was looking over the DemoScenes, so I should still have a dialogue manager in each scene right? Then it will replace them as you said before.
Should I also have a separate canvas for my UI in that case? Right now, I had it all under the Dialogue Manager Canvas so should I put the UI under the EventSystem?
Also when it comes to sound, I am guessing that I can also put that under the Dialogue System so that it persists throughout the game. I had sound objects for each scene that held the sounds they needed but I think a persistent object that keeps the sound together might be a better system.
Now that I know the correct way to override (from a previous issue you helped me on) I should be good to go on that! Lots of code changes to make.
Putting a Dialogue Manager in each scene is optional. It makes it easier to playtest since you can enter play mode directly from any scene. I recommend making a single Dialogue Manager prefab (for example, a prefab variant of the base Dialogue Manager prefab) and dropping that prefab into your scenes. That way you can make changes to the prefab and it will be reflected in all scenes.
If you use scene-specific dialogue UIs, use a separate Canvas in the scene.
Yes, you can put globally-used sound objects under the Dialogue Manager. Keep in mind that you can't point scene-specific UnityEvents to them, but other than that it's a good way to keep them accessible.
Putting a Dialogue Manager in each scene is optional. It makes it easier to playtest since you can enter play mode directly from any scene. I recommend making a single Dialogue Manager prefab (for example, a prefab variant of the base Dialogue Manager prefab) and dropping that prefab into your scenes. That way you can make changes to the prefab and it will be reflected in all scenes.
If you use scene-specific dialogue UIs, use a separate Canvas in the scene.
Yes, you can put globally-used sound objects under the Dialogue Manager. Keep in mind that you can't point scene-specific UnityEvents to them, but other than that it's a good way to keep them accessible.
I just made the change to the prefab now, I'll go ahead adding replacing the ones in my scenes before as they were all different.
So for globally-used sound objects (background music/sound effects) what would I need to do to have them work between scenes? Right now I have a sort of MP3 player in the MainScene that can switch the music from that scene between a couple selections. This music also starts after completing the tutorial currently with the sequence below.
I have a separate background music (set to Play On Awake and Loop) for the MainMenuScene that stops after switching scenes due to the object being destroyed.
In the case of it being global, would I just need to disable it as it switches scenes, then start up the new music?
Yes, although I recommend writing some kind of dedicated MusicManager script. You can put this script on the Dialogue Manager or some other GameObject that survives scene changes. It could have methods such as PlayMainMenuTheme(), PlayIntroTheme(), PlayDefaultGameplayTheme(), etc.
Then you can write custom sequencer command(s) to change themes and/or drop a script into a scene that switches themes.
It'll be easier to manage your background music through a single manager script than a loose collection of individual audio sources.
Tony Li wrote: ↑Wed Jan 12, 2022 2:52 pm
Yes, although I recommend writing some kind of dedicated MusicManager script. You can put this script on the Dialogue Manager or some other GameObject that survives scene changes. It could have methods such as PlayMainMenuTheme(), PlayIntroTheme(), PlayDefaultGameplayTheme(), etc.
Then you can write custom sequencer command(s) to change themes and/or drop a script into a scene that switches themes.
It'll be easier to manage your background music through a single manager script than a loose collection of individual audio sources.
I'll work on making a MusicManager script now. For SFX and other in-game sounds like button clicks would it be good to also include those in the script as well?
I think so. You could generalize it into an AudioManager script, with methods to transition between different background music and other methods to play sound effects.