Page 1 of 2
Save System
Posted: Sun Dec 09, 2018 9:18 pm
by nitrox32
First, Dialogue system is fantastic! I just can't stop exploring all of it's features. Now that I understand the basics of conversation I've been looking at the Save System. My first goal is to set up a checkpoint system. So far I have set up an empty game object in my scene and added the Save System, Json Data Serializer and Player Prefs Saved Game Data Storer components. I have also created a game object with a trigger, Save System Methods and Trigger Event. Each component is setup according to the Save System Manual. At runtime I run into the trigger and the console shows that I have saved the game as Save1. From here I go to my Menu scene and set up a Save System game object as before and set my Load Button to load Save1. Everything works as is should except the when the scene loads it briefly displays the original starting position (before the save) before it switches to the Save1 position. Would the Standard Scene Transition Manager assist with this by fading in and out to cover this strange behavior?
Re: Save System
Posted: Sun Dec 09, 2018 11:31 pm
by Tony Li
Yes. You got it. See DemoScene1 for an example.
In DemoScene1, I just put the Save System stuff on the Dialogue Manager GameObject. The Dialogue Manager's Canvas has a SceneFaderCanvas, which is a fullscreen black overlay with an animator that can fade it in and out. The Standard Scene Transition Manager component on the Dialogue Manager is configured to play the SceneFaderCanvas's fade in/out animations.
Using this setup, when loading a saved game GameObjects have a chance to get into position while the screen is still faded to black.
Re: Save System
Posted: Mon Dec 10, 2018 8:30 pm
by nitrox32
Thanks. Now when I am changing scenes the cursor which was disabled by unticking Detect Mouse Control appears when the new scene is loading and still is still visible in the new scene even though I have Detect Mouse Control unticked in the new scene. Any way to prevent this from happening?
Re: Save System
Posted: Mon Dec 10, 2018 9:51 pm
by Tony Li
Hi,
If your second scene also has a Dialogue Manager (which at runtime will probably be replaced by the Dialogue Manager from the original scene), make sure Detect Mouse Control is unticked on it, too. You can also untick Control Cursor State. This will prevent the Input Device Manager component from touching the mouse cursor at all.
If you're using any other assets in your project, make sure they're configured so they won't make the cursor visible when changing scenes. The Dialogue System's Input Device Manager doesn't constantly hide or show the cursor. If Control Cursor State is ticked, then it will only issue one command to show or hide the cursor at the moment that it detects a change in mouse control.
Re: Save System
Posted: Tue Dec 11, 2018 9:48 pm
by nitrox32
Thanks for getting back to me. Problem solved. I needed to untick Pause During Transition in the Standard Scene Transition Manager. My next question might be a bit difficult to ask as I'm not exactly sure how to explain the big picture as there are many parts. So instead of trying to explain everything I'll simply start with my menu buttons. Currently I have a "New Game" button and a "Load Game" button. With the New Game button I want to clear any saved games and start fresh in the opening scene. I noticed in the Scripting section of the documentation there is a method called RestartGame which sounds like exactly what I want. I'm not the best coder so is there a way to use this within the editor?
Re: Save System
Posted: Tue Dec 11, 2018 10:12 pm
by Tony Li
Hi,
SaveSystem.RestartGame("
sceneName") resets the dialogue database's runtime values to the original design-time values and then loads
sceneName. But it doesn't delete any old saved games. It just starts a new one.
In a game that allows multiple save slots, this is the way it's normally done. You can start a new game, then go back to the main menu, and then load some older saved game if you want.
In a game that only has one save slot and does checkpoint saves, typically you'll delete the existing saved game before restarting a new game. Use
SaveSystem.DeleteSavedGameInSlot(#). For example, let's say you always save in slot 1. To delete the existing saved game (if there is one) and start a new game in the scene "First Gameplay Scene":
Code: Select all
using PixelCrushers; // This lines goes at the top of your script.
...
SaveSystem.DeleteSavedGameInSlot(1);
SaveSystem.RestartGame("First Gameplay Scene");
If you allow multiple saved game slots and you want to delete all existing saved games, you'll need to use a loop. For example, to delete slots 1 - 5:
Code: Select all
for (int slot = 1; slot <= 5; slot++)
{
SaveSystem.DeleteSavedGameInSlot(slot);
}
Re: Save System
Posted: Wed Dec 12, 2018 12:21 pm
by nitrox32
Great, that makes sense. My next question has to do with moving between scenes, say an outdoor scene and an indoor scene such as going into a building. Currently my New Game button takes me to a position in the outdoor scene. When I walk up to the door of a building the I have a collider that loads the building interior and a checkpoint that saves the game at the players start position inside the interior scene into slot one. The console confirms this. When I go to my menu scene an select the load button the interior scene loads as expected. I also have a loadscene trigger at the door in the inside scene to the outside scene mentioned earlier (the same as the new game scene). When I step into that trigger the outdoor scene loads but the player is reset to it's "new game" position (as from the menu) not the position outside the door of building. How do I get the the player to go to a position just outside the door instead of the its original "new Game" position? BTW, I am using Opsive TPC, should I be using UCC Saver in some way?
Re: Save System
Posted: Wed Dec 12, 2018 2:15 pm
by Tony Li
Hi,
Please import the updated integration package available through Opsive's integrations window.
Make sure your player is tagged Player and has a UCCSaver component.
In the outside scene, place an empty GameObject at the position where you would like the player to appear. For example, let's say the scene is named "Outside" and the empty GameObject is named "Doorstep".
To change from the inside scene to the outside scene, use the
LoadScene() sequencer command,
SaveSystem.LoadSceneAtSpawnpoint() C# method, or Save System Methods component's LoadScene() method. Whichever one you use, specify the empty GameObject name after an "@" sign, such as:
Code: Select all
// Load "Outside" scene and place player at Doorstep:
SaveSystem.LoadScene("Outside@Doorstep");
The latest integration package (12/12/2018) updates UCCSaver so it observes the spawnpoint if specified.
Re: Save System
Posted: Wed Dec 12, 2018 8:19 pm
by nitrox32
Thanks for getting back to me. Still not working. This is what I've done:
1) Imported the updated integration from Opsive.
2) Added a UCC Saver component to the characters in both the inside and outside scene and added a player tag to each.
3) Created an empty GameObject called Doorstep and placed it next to the door of my building in the "Outside" scene.
4) Created a script that would load the outside scene upon entering a trigger
Code: Select all
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using PixelCrushers;
public class PixelCrushersLoadScene : MonoBehaviour
{
void OnTriggerEnter(Collider collider)
{
if (collider.tag == "Player")
{
SaveSystem.LoadScene("OpeningScene@Doorstep");
}
}
}
5) Run the Indoor scene and enter the trigger. The scene begins to load the outdoor scene. The console displays this:
Save System: Loading scene OpeningScene [spawn at Doorstep]
UnityEngine.Debug:Log(Object)
PixelCrushers.<LoadSceneCoroutine>c__Iterator4:MoveNext() (at Assets/Plugins/Pixel Crushers/Common/Scripts/Save System/SaveSystem.cs:586)
UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
PixelCrushers.SaveSystem:LoadScene(String) (at Assets/Plugins/Pixel Crushers/Common/Scripts/Save System/SaveSystem.cs:580)
PixelCrushersLoadScene:OnTriggerEnter(Collider) (at Assets/Scripts/PixelCrushersLoadScene.cs:12)
Result: The player still ends up in it's original position in the outside scene as if I were starting the scene by itself.
Re: Save System
Posted: Wed Dec 12, 2018 8:49 pm
by Tony Li
Hi,
Please import this version of UCCSaver:
DS2_UCCSaver_2018-12-12.unitypackage
It adds a
Debug checkbox. Tick the checkbox on the character in both scenes, and try again. You should see something like:
- UCC Saver on name moving character to spawnpoint Doorstep
If you see this instead:
- UCC Saver on name (tag=Player) restoring saved position x,y,z
then there's something funny going on.
If you see the second line above but the tag isn't "Player", double-check that you set the Tag dropdown on the character's GameObject to Player.
If you don't see either line, there are a few possibilities. (1) Double-check that the character has a UCCSaver component. (2) If the character has multiple Saver components, make sure they all have unique keys. You can generally do this by ticking the Append Saver Type To Key checkbox.
If none of that helps, please feel free to send a reproduction project to tony (at) pixelcrushers.com. I'll be happy to take a look.