Forum rules - please read before posting.

AC's Save System/Cloud Saving

I'm trying to get my head around the whole save system and how I'd implement a system that uploads AC's saved data to the cloud automatically when AC saves.

I've read the 'custom save data' section of the manual over and over but I'm not sure where I need to add the code that would achieve what I'm after - that's if I'm understanding the concept of it correctly to start with. In my head, the cloud system works by uploading/synching the save data as it happens when AC saves the game. Am I right in thinking this? And I presume it'd be a similar process for loading a saved game, if I'm right?

Would cloud saving be a case of just uploading the saved file to the cloud or am I totally on the wrong path?

«1

Comments

  • Technically, cloud saving merely refers to storing save-files online. Whether they are copies of files that are also made locally, or the only place they are stored, is a design decision.

    Either way, it's the "Custom save formats and handling" chapter of the Manual you'll want. The "Custom save data" chapter deals with the contents of save-files, whereas this deals with where such data is stored.

    AC separates the location and format of save files - its the former you want to change. This involves writing a new class that implements iSaveFileHandler, and setting it as the chapter covers, i.e.:

    SaveSystem.SaveFileHandler = new MyClassName ();
    

    For two examples, you can see AC's SaveFileHandler_SystemFile and SaveFileHandler_PlayerPrefs scripts, that store files on the system and in Unity's PlayerPrefs respectively.

  • Thanks, Chris. I'm getting there. Now, in my custom script, which saved 'keys' do I use to send to the cloud?

    This link: https://github.com/rkhadder/XboxLiveConnectedStorageSample gives the general idea of how it works.

    I've set the xbox user variables etc but which saved AC elements/keys do I need to add into the following 'some value' line?:

    data[BLOB_NAME] = System.Text.Encoding.Unicode.GetBytes(/* some value */);

    I think this is the only thing I need to do now so any guidance would be VERY much appreciated - thank you! :)

  • The SaveFileHandler's Save function's dataToSave parameter is the raw data - this'll be the "some value".

  • edited November 2022

    Hi Chris - so it would literally be dataToSave?

    data[BLOB_NAME] = System.Text.Encoding.Unicode.GetBytes(dataToSave);

    I'm sorry, I'm not sure what the parameters for dataToSave actually are.

  • Renaming BLOB_NAME to match your intended key, but yes - inferring from the docs, that's where I'd expect dataToSave would go.

  • Thanks Chris.

    What I'm struggling with is which scripts do I actually have to edit? Do I just edit the SaveFileHandler_PlayerPrefs script and not touch SaveSystem or iSaveFileHandler scripts? And if so do I just modify the SaveFileHandler_PlayerPrefs script or wipe it and replace it with the Xbox stuff? I'm REALLY sorry, this kind of scripting really isn't my strong point :/

  • I'd strongly advise having a dedicated Xbox developer on your team if you're publishing to that platform.

    To answer your question though: you don't modify any of the script - the one you mentioned can be used as an example. You'd create your own and then have AC rely on that instead of the one it normally does.

    The quick-start way would be to duplicate SaveFileHandler_PlayerPrefs, rename it (and the class name inside) to e.g. SaveFileHandler_CloudStorage, and then have AC point to it on startup.

    This can be done via another script with the following function, placed on AC's PersistentEngine prefab:

    using UnityEngine;
    using AC;
    
    public class EnableCloudSaving : MonoBehaviour
    {
    
        void Awake ()
        {
            SaveSystem.SaveFileHandler = new SaveFileHandler_CloudSaving ();
        }
    
    }
    

    That'll get AC to then use your new SaveFileHandler_CloudStorage script when it comes to writing/reading save data from files. You can then modify this as needed.

  • Thanks Chris. Yeah, it's just little me on this project - I can't afford to pay a developer so it's all down to me. I see it as a learning curve.

    Thanks for your help, it's cleared something up :)

  • edited November 2022

    Does the iSaveFileHandler script become unused altogether? I'm just confused why we need to state "new SaveFileHandler" if it's not still linked to the new SaveFileHandler.cs file in any way. Do we still use the SaveFileHandler.cs save/load features? How does the game now what and when to save? We're using autosave. Yeah, I think it's safe to say this is completely out of my depth. The last hurdle too :(

  • iSaveFileHandler is an interface - it is used by other SaveFileHandler scripts to provide Save and Load functions.

    AC separates its file-handling and file-format duties with separate interfaces. SaveFileHandler merely deals with where data is saved - not what that data is. When your game saves will be the same as before.

  • edited November 2022

    I'm still confused. How are autosaves handled? I imagine AC is doing this behind the scenes, so how and where are these calls to autosave made?

    If I'm using a custom script then why is AC still autosaving in the background? I do want it to autosave, but I'm confused :(

    I created a SaveFileHandler_CloudStorage file but keep getting errors saying it doesn't contain the script definitions set in iSaveFileHandler - but why's it even requiring these if it's a custom script? I'm baffled. The functions in my custom script are different to the ones set by default in the iSaveFileHandler. Changing those unfortunately results in more errors.

    The whole custom save thing is just extremely confusing to me. I've grasped everything else apart from this. It seems like it should be relatively straight forward but for the life of me I just can't get any of it to build, let alone function.

  • Again, when AC autosaves is separate from where that data is put. The creation of a custom SaveFileHandler has no bearing on AC autosaving.

    AC autosaves in two ways:

    • By checking Autosave after? in a Cutscene's properties
    • By using the Save: Save or load Action

    iSaveFileHandler is an interface, which means any script that derives from it must contain the functions it defines. This is a C# concept and not related to AC. You must define all of the functions in the interface - though they can be empty for the purposes of testing.

  • Can the functions in iSaveFileHandler be changed? Would that break any of AC's saving abilities?

  • edited November 2022

    EDIT: That was meant for your inbox, sorry.

  • This technique relies on coroutines, so you'd need to have a separate MonoBehaviour script that handles the saving, with the SaveFileHandler referencing it as needed.

    Is "connected storage" where you want to be saving to?

  • Yes, the Connected Storage is Microsoft's Cloud; that's where it would be getting saved and loaded from.

    Basically when the gamer autosaves I'm wanting it to send the save data to the Connected Storage/Cloud. And when the player resumes I'm wanting it to load that save data from it.

  • Would autosaving be the only saving done?

  • Yes, just autosave. There are no other save options given to the player.

  • You mentioned in your PMs that you already had the signing-in handled. Is that to say you already have a script that's handling the XboxLive communications?

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.