Page 1 of 1
HasSavedGameInSlot only works half the time.
Posted: Fri May 31, 2019 7:28 pm
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.
Re: HasSavedGameInSlot only works half the time.
Posted: Sat Jun 01, 2019 8:06 am
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?
Re: HasSavedGameInSlot only works half the time.
Posted: Sun Jun 02, 2019 1:15 am
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
I hope this helps a little more in understanding it.
Re: HasSavedGameInSlot only works half the time.
Posted: Sun Jun 02, 2019 2:00 am
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
Re: HasSavedGameInSlot only works half the time.
Posted: Mon Jun 03, 2019 9:28 pm
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.
Re: HasSavedGameInSlot only works half the time.
Posted: Sat Jun 08, 2019 5:24 pm
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.
Re: HasSavedGameInSlot only works half the time.
Posted: Sat Jun 08, 2019 5:55 pm
by HeroicMaou
It's nothing urgent so I don't mind waiting for the asset store update. Thank you though for the incredible support!