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.
HasSavedGameInSlot only works half the time.
-
- Posts: 8
- Joined: Thu May 30, 2019 6:53 pm
Re: HasSavedGameInSlot only works half the time.
Hi,
What Save Game Data Storer component are you using? If you're using PlayerPrefsSavedGameDataStorer, are you perhaps clearing PlayerPrefs before/after runs?
What Save Game Data Storer component are you using? If you're using PlayerPrefsSavedGameDataStorer, are you perhaps clearing PlayerPrefs before/after runs?
-
- Posts: 8
- Joined: Thu May 30, 2019 6:53 pm
Re: HasSavedGameInSlot only works half the time.
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
My code starts like this
The save games are stored in the proper folder and are named
For a more complete list, it looks like this on my Dialogue Manager
- DialogueSystemSaver
DiskSavedGameDataStorer
JsonDataSerializer
SaveSystem
LevelManager
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);
}
- save_0.dat
saveinfo.dat
-
- Posts: 8
- Joined: Thu May 30, 2019 6:53 pm
Re: HasSavedGameInSlot only works half the time.
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.
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
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));
}
}
Re: HasSavedGameInSlot only works half the time.
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.
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.
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.
-
- Posts: 8
- Joined: Thu May 30, 2019 6:53 pm
Re: HasSavedGameInSlot only works half the time.
It's nothing urgent so I don't mind waiting for the asset store update. Thank you though for the incredible support!