Loading Game

Announcements, support questions, and discussion for the Dialogue System.
jrose1184
Posts: 35
Joined: Mon Jan 22, 2024 2:35 pm

Loading Game

Post by jrose1184 »

Hi. Im creating a main menu scene for when the game starts. I have 2 buttons "new Game" and "Continue.

So for start new game i have done

public void NewGame()
{
PlayerPrefs.DeleteAll();

// Use the Save System to reset the saved game
PixelCrushers.SaveSystem.ResetGameState();

SceneManager.LoadScene("BeverageHills");
SceneManager.LoadScene(sceneToLoad, LoadSceneMode.Additive);
}

That seems to work i just want to check that it will wipe all game data but wont delete any dialouge trees or quests etc...

But the issue tht i got is when i press continue i have done

public void Continue()
{
Debug.Log("Continue button");
PixelCrushers.SaveSystem.LoadFromSlot(0);
}

but i get this message


Save System: No SavedGameDataStorer found on Save System. Adding PlayerPrefsSavedGameDataStorer.

So am i doing this correctly and how do i know what slot is the correct one. Im using the demo menu that it comes with for saving and loading.

But i also want it to work on the game start up menu with my own code if possible?

Sorry also does the new game also delete player prefs just incase your code is also using some player prefs.

Thanks.
User avatar
Tony Li
Posts: 22655
Joined: Thu Jul 18, 2013 1:27 pm

Re: Loading Game

Post by Tony Li »

Hi,

> That seems to work i just want to check that it will wipe all game data but wont delete any dialouge trees or quests etc...

That's correct. Make sure your Dialogue Manager (or whichever GameObject has the Save System component) also has a Dialogue System Saver, Json Data Serializer, and PlayerPrefs Saved Game Data Storer.


> Save System: No SavedGameDataStorer found on Save System. Adding PlayerPrefsSavedGameDataStorer.

You may be getting this warning if there's no Save System component. Typically you'll put this component on the Dialogue Manager, but you can also have it separate, such as if you've imported the preconfigured SaveSystemPrefabs package available on the Dialogue System Extras page. In any case, make sure there is only one Save System.


> But i also want it to work on the game start up menu with my own code if possible?

That's fine. Use the code like you already are -- SaveSystem.SaveToSlot(#) and SaveSystem.LoadFromSlot(#).

> Sorry also does the new game also delete player prefs just incase your code is also using some player prefs.

No. Use SaveSystem.DeleteSavedGameInSlot(#) to delete the saved game data.
jrose1184
Posts: 35
Joined: Mon Jan 22, 2024 2:35 pm

Re: Loading Game

Post by jrose1184 »

Awesome thank you.

I am still alittle bit lost. So i am going to use the save prefab from you extras page. I think starting a new game i have no issues with. Im still lost on how i can continue a game.

So for instance i am in my scene i press esc and i save the game i move then i press esc and then load. This does all the work i need it to do. So i can see that my game is loading and saving.

I then changed my max save slots to 1.

then back onto my game menu when i press the continue button im still geting no save slots.

so in my start folder i added.

void Start()
{
for (int slot = 0; slot < 999; slot++)
{
if (SaveSystem.HasSavedGameInSlot(slot))
{
Debug.Log($"Slot {slot} has a saved game.");
}
}
}
Save System: No SavedGameDataStorer found on Save System. Adding PlayerPrefsSavedGameDataStorer.
UnityEngine.Debug:Log (object,UnityEngine.Object)

So i still not sure on how i can get this to work.

I would also like to get the continue button to work with the loading scene aswell from the prefab.

Many thanks.
User avatar
Tony Li
Posts: 22655
Joined: Thu Jul 18, 2013 1:27 pm

Re: Loading Game

Post by Tony Li »

Hi,

If you're still seeing this message:

"Save System: No SavedGameDataStorer found on Save System. Adding PlayerPrefsSavedGameDataStorer."

Then I suspect your scene has more than one Save System component. Since you're using the Save System prefab, which has this component, make sure your Dialogue Manager GameObject doesn't also have a Save System component.

You could put a script like this on your Continue button:

Code: Select all

using UnityEngine;
using UnityEngine.UI;
public class ContinueButton : MonoBehaviour
{
    void Start()
    {
        var button = GetComponent<Button>();
        button.interactable = PixelCrushers.SaveSystem.HasSavedGameInSlot(1);
        button.onClick.AddListener(() => PixelCrushers.SaveSystem.LoadFromSlot(1));
    }
}
It sets the Continue button interactable only if there's a saved game in slot 1.

It also configured the button's OnClick() event to load slot 1.

(Or you could use the free Menu Framework addon available on the Extras page.)
jrose1184
Posts: 35
Joined: Mon Jan 22, 2024 2:35 pm

Re: Loading Game

Post by jrose1184 »

Hi Sorry still not working just to confirm i am not using the dialogue manager inside this scene will that be an issue why it wont find any saved data? Im only using Dialogue Manger inside game play scenes.

https://paste.ofcode.org/GcdFpES5L6bCJSWyLHfkE9

Here is my Script.

The main reason i have not included the manager is i dont wont to beable to pres esc top open the menu - that was for ingame only.

Image

https://postimg.cc/tY6htbtZ
User avatar
Tony Li
Posts: 22655
Joined: Thu Jul 18, 2013 1:27 pm

Re: Loading Game

Post by Tony Li »

Hi,

Are you saving the game into slot 0?

When your script's Start() method runs, do you see "Slot 0 has a saved game"?
jrose1184
Posts: 35
Joined: Mon Jan 22, 2024 2:35 pm

Re: Loading Game

Post by jrose1184 »

Hi,

I made a quick video. Prob easier for me to explain.

User avatar
Tony Li
Posts: 22655
Joined: Thu Jul 18, 2013 1:27 pm

Re: Loading Game

Post by Tony Li »

Hi,

Let's try this:

1. Keep the Dialogue Manager in the first scene. Since your Dialogue Manager has a Save System component, do not put the Save System prefab in the scene.

2. On your continue button, add the script I provided in this post, except change the slot number from 1 to 0 (in two places). Leave the button's OnClick() event empty.

3. Play the Main Menu scene and click Continue. When you click Continue, it should unload the Main Menu scene and load the scene in which you saved your game. In your video, I see that Beverage Hills, TestScene1, and Main Menu are all loaded, which doesn't seem like it's what you'd want to do.
jrose1184
Posts: 35
Joined: Mon Jan 22, 2024 2:35 pm

Re: Loading Game

Post by jrose1184 »

Thanks for you help.

So i done them steps but when i click continue i get nothing there is no console logs to report.

So just to confirm.

I left the Dialogue Manger in the scene.

I removed the onlick for the continue button

and i added a var

public Button continueButton;

and inside start i added

void Start()
{
continueButton.interactable = PixelCrushers.SaveSystem.HasSavedGameInSlot(0);
continueButton.onClick.AddListener(() => PixelCrushers.SaveSystem.LoadFromSlot(0));
}

But no luck im affraid.
jrose1184
Posts: 35
Joined: Mon Jan 22, 2024 2:35 pm

Re: Loading Game

Post by jrose1184 »

void Start()
{

if (continueButton != null && PixelCrushers.SaveSystem.HasSavedGameInSlot(0))
{
continueButton.interactable = true;

continueButton.onClick.AddListener(OnContinueButtonClicked);
Debug.Log("Event listener added to the continue button.");
}
else
{
continueButton.interactable = false;
Debug.LogError("No saved game found, or continueButton is not assigned.");
}
}


private void OnContinueButtonClicked()
{

Debug.Log("Continue button clicked!");
}

The return on this is Debug.LogError("No saved game found, or continueButton is not assigned.");
Post Reply