HasSavedGameInSlot only works half the time.

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
HeroicMaou
Posts: 8
Joined: Thu May 30, 2019 6:53 pm

HasSavedGameInSlot only works half the time.

Post by HeroicMaou »

So I have a main menu where I'm supposed to detect if I have a save data and if I do, skip the main menu and continue forward to the game. If I don't, I go through a somewhat character creation kind of thing. My issue here is that HasSavedGameInSlot only works sometimes. In the same Play Session to be exact. If I stop the play then restart, it doesn't detect the save game data anymore.

I'm really stumped as to why. Any insight as to why? I can post any screenshots, code used, etc if needed.
User avatar
Tony Li
Posts: 22055
Joined: Thu Jul 18, 2013 1:27 pm

Re: HasSavedGameInSlot only works half the time.

Post by Tony Li »

Hi,

What Save Game Data Storer component are you using? If you're using PlayerPrefsSavedGameDataStorer, are you perhaps clearing PlayerPrefs before/after runs?
HeroicMaou
Posts: 8
Joined: Thu May 30, 2019 6:53 pm

Re: HasSavedGameInSlot only works half the time.

Post by HeroicMaou »

I'm using Disk Saved Game Data Storer and the Json Data Serializer.
For a more complete list, it looks like this on my Dialogue Manager
  • DialogueSystemSaver
    DiskSavedGameDataStorer
    JsonDataSerializer
    SaveSystem
    LevelManager
and it's in this order on the object as well. At first it worked fine, however when I started to incorporate the main menu, it started to break. Now I can't even get it to work the way it use to.
My code starts like this

Code: Select all

private void Start()
    {
        keyboard.Active(false);
        if (SaveSystem.HasSavedGameInSlot(0))
        {
            SaveSystem.LoadFromSlot(0);
        }
        else
        {
            keyboard.Active(true);
            StartCoroutine(SelectObject(keyboard.firstSelect));
        }
        string s = DialogueLua.GetActorField("Player", "Display Name").asString;
        Debug.Log(s);
    }
The save games are stored in the proper folder and are named
  • save_0.dat
    saveinfo.dat
I hope this helps a little more in understanding it.
HeroicMaou
Posts: 8
Joined: Thu May 30, 2019 6:53 pm

Re: HasSavedGameInSlot only works half the time.

Post by HeroicMaou »

I think I solved this.
So I was thinking back about when my code in a previous project needed me to wait a frame then start everything. Surely enough, this worked here as well.

Code: Select all

    private void Start()
    {
        keyboard.Active(false);
        StartCoroutine(DelayedStart());
    }
    IEnumerator DelayedStart()
    {
        yield return new WaitForEndOfFrame();
        if (SaveSystem.HasSavedGameInSlot(0))
        {
            SaveSystem.LoadFromSlot(0);
            StopCoroutine(DelayedStart());
            yield break;
        }
        else
        {
            keyboard.Active(true);
            StartCoroutine(SelectObject(keyboard.firstSelect));
        }
    }
Waiting till the end of the frame works. It started to detect and return my saved games. I've been able to Save and Load properly. I guess I should of tried more things before posting, it's how my problems usually go :lol:
User avatar
Tony Li
Posts: 22055
Joined: Thu Jul 18, 2013 1:27 pm

Re: HasSavedGameInSlot only works half the time.

Post by Tony Li »

DiskSavedGameDataStorer loads the list of saved game files in Start(). Your trick to wait until end of frame gives it time to run first. It works half the time because Unity doesn't guarantee the other in which different scripts' Start() methods run (unless you manually set them using Script Execution Order).

It looks like I can move it to Awake() in the upcoming version 2.1.7, after which you can remove the DelayedStart() from your script if you want.
User avatar
Tony Li
Posts: 22055
Joined: Thu Jul 18, 2013 1:27 pm

Re: HasSavedGameInSlot only works half the time.

Post by Tony Li »

Version 2.1.7 has been released. It's available on the Pixel Crushers customer download site right now (PM me your Unity Asset Store invoice number if you need access), or you can wait 3-10 business days and download it from the Unity Asset Store.
HeroicMaou
Posts: 8
Joined: Thu May 30, 2019 6:53 pm

Re: HasSavedGameInSlot only works half the time.

Post by HeroicMaou »

It's nothing urgent so I don't mind waiting for the asset store update. Thank you though for the incredible support!
Post Reply