Saving between scenes doesn't work

Hi there,

So, when I save and load inside the same scene, everything works fine. But when I transition between scenes, nothing gets saved anymore, nor my inventory and equipment, nor my health, XP etc. I checked that my Player has the same unique ID in both scenes, the only clue I have so far are these errors

Something seems to be missing when restoring my inventory state, maybe causing everything else to fail to restore, but I think my debugging skills are still too limited to find the problem…

Any help would be greatly appreciated !

That is actually a strange error message, because we’re not dealing with a GameObject in InventoryItem.GetFromID(), and the error message seems to indicate that the error is on this line:

var itemList = Resources.LoadAll<InventoryItem>("");

Have you made any changes to GetFromID() in InventoryItem.cs?

I just checked it against the original version in the package, I don’t see any difference. Indeed, the error seems to come from this line.

OK, so I noticed I get the same error messages when saving and loading without transitioning between scenes, but the saving system works fine nonetheless. The problem only happens when I go from one scene to another, nothing gets restored as it should. The saving seems to happen, since I get the correct message in the console, so I suppose it’s the restoring part that’s broken. But I still have no clue why.

I’m going to skip the 20 questions phase here, as I’m not even sure where to start. Zip up your project and upload it to https://gdev.tv/projectupload and I’ll take a look and see if I can figure out what’s going on.

Hello Brian, I just uploaded my project as requested. Thank you very much for doing this, I guess it’s not the easiest part of the job going through someone else’s files and hunting for the mistakes they’ve made. I’m sure I’ll learn something valuable from your diagnosis, and maybe some fellow students will as well !

So this one was tricky, and it took me quite a while to figure out.

The most confusing part for me wasn’t actually the error message that started it all, it was the fact that when transitioning between scenes, RestoreState was never getting called at all on Inventory/health, etc, but it was getting called when restarting the game.

Portal looks normal, and debugs indicated that Portal simply stopped working on the call to Load.

That left me heading to SavingWrapper, where I found that Load() read

public void Load()
{
      GetComponent<SavingSystem>.LoadLastScene();
}

So what’s happening is that when Portal calls SavingWrapper.Load(), SavingWrapper.Load() Loads the last scene, but because it’s calling LoadLastScene like a method instead of a Coroutine, all that effectively happens is that the scene is reloaded.

So I made the following changes to SavingWrapper.cs:
In Update(), I changed the call to Load() to

StartCoroutine(LoadLastScene());

Then for Load, I changed the contents to

GetComponent<SavingSystem>().Load(defaultSaveFile);

Interestingly enough, while this now made the saving and loading work correctly, the warning messages are still appearing when first loading with a save file, but they appear to have no impact whatsoever on saving and loading the game once the changes listed above are implemented.

1 Like

Thank you very much ! I wouldn’t have figured it out by myself. Using your solution, I still had to change the Load() method in the Saving System script from private to public so I could access it from the Saving Wrapper, I don’t know if this is normal, but anyway, it works !

That’s correct, I forgot ot mention that change.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms