Forum rules - please read before posting.

Issues with Save System - Scene vs Global Data

Hi, I'm trying to wrap my head around Save Systems in AC, but I've ran into some issues.

I have a CharacterManager Singleton which keeps track if the character is dead or not.
pasteall.org/1459940/csharp

My Remember script looks pretty much like this:
pasteall.org/1459955/csharp

Saving Global Data looks like this:
pasteall.org/1459960/csharp

I need the data in CharacterManager to be saved and persistent throughout all scenes (just one instance of the whole thing).
At first I thought I can use custom Remember Script to save data. It worked fine at first, but now I realised that the data saved/loaded is specific to each scene. So for example if CharacterManager.instance.isDead[0] = true in one scene, then it's still = false in any other scene (and vice versa). If I understand correctly, this is correct behaviour of Custom Remember Script - it remembers values separately for each scene.

So I've tried saving the data using Saving custom global data tutorial. The data is now saved/loaded correctly, no matter what scene you save it in. Again, if I'm understanding this correctly, then that's the expected behaviour of each of the saving methods.

Using the Global Save however, I do have one, quite big issue. Every time I save the game, all of the saves get the same value saved - no matter what save slot I pick, all save slots are overwritten.

For example:
I make a save in slot 1 and the data is CharacterManager.instance.isDead[0] = false - if I change the bool to true and load, then the data is loaded correctly, back to false.
If I create another save, this time in slot 2 and the data this time around is CharacterManager.instance.isDead[0] = true and then I load the save 1, then the data is loaded as true. From what I observed, the most recent save overwrites all other saves. I hope that makes sense.

The debug window shows correct save slots being saved/loaded. For testing the Global Save script, I did remove Remember Script beforehand and vice versa, so that only one of the methods is in use at a time.

I'm not really sure how to fix this. Am I missing something simple here?

Unity Version: 2018.2.18f1
AC Version:1.65.2

Comments

  • You're correct about the usage of Remember scripts - they're specific to the scene they're placed in.

    Your SaveCharacterManager script just looks to be passing data back and forth between itself and the CharacterManager instance - there's no reference to AC's Global Variables system, which is what the tutorial makes use of to actually save the data.

    Global Variables are saved automatically, so the method works by transferring custom data to a global variable (or variables) before saving, and retrieving it from there after loading. You need to write a way of transferring the array's data to the Variables system - not to a local variable within SaveCharacterManager.

  • Ahh... I thought that saving to a Global Variable was just an example, and not a vital part of the method. I have a lot of arrays that would need saving, so transferring custom data to Global Variables would be a very tedious task and it seems it would be very easy to mess things up later on.

    I've tried setting up a custom Save System:
    Character Data to save:
    pasteall.org/1462208/csharp

    Save the data to a file:
    pasteall.org/1462246/csharp

    And then use it through SaveCharacterManager attatched to PersistentEngine:
    pasteall.org/1462219/csharp

    So my idea was that this would work in conjunction with the built in AC Save System, and... It seems to be working fine (unless that's just a lucky bug or something?). The problem is again, that the save overwrites itself no matter if I save it on slot 1 or 2.

    In this case, I can easily see why that's happening though - my custom save always writes data in the same path. What I would need is to be able to determine what button (save slot) the player clicked on, and then create separate paths based on that. Would something like this work?

    And... I'm not sure if this could create any problems in the long term. It seems a bit weird to have two save systems working at the same time. Would there be any other way to do this? Remember Scripts won't work (because I need the data to be consistent throughout all scenes) and I would really rather avoid creating hundreds of Global Variables to save my arrays.

  • edited January 2019

    What I would need is to be able to determine what button (save slot) the player clicked on, and then create separate paths based on that

    I'll admit that the events should ideally include the save ID, and I'll give that some thought.

    I would really rather avoid creating hundreds of Global Variables to save my arrays.

    There's no need to - you can compact your data into a string and store it in a single string variable. AC does this a lot - see, for example, the way Animator parameters are saved in the Remember Animator script.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.