Forum rules - please read before posting.

continue from last save + steam cloud saves

I have Steam cloud saves set up and working, but my continue from last save button doesn't work as intended. the continue button loads the last save made on that device, so if I save, change device, then continue it loads the 'wrong' save. I think this is because cloud saves share the data in the save file location, and the info for the last save is saved in playerprefs? Is it somehow possible to store the last save ID info with the save files instead, so they can be synched?

AC 1.75.8, Unity 2020.3.22f1

Thanks :o)

Comments

  • You're right - currently, the Options Data keeps track of which save was the last to be recorded.

    It's possible, however, to have a custom script that iterates through the available saves to get the latest by reading their updateTime value:

    using UnityEngine;
    using AC;
    
    public class CustomContinueGame : MonoBehaviour
    {
    
        public void ContinueGame ()
        {
            KickStarter.saveSystem.GatherSaveFiles ();
            int maxTime = 0;
            SaveFile mostRecentSave = null;
    
            foreach (SaveFile saveFile in KickStarter.saveSystem.foundSaveFiles)
            {
                var time = -saveFile.updatedTime;
                if (time > maxTime)
                {
                    maxTime = time;
                    mostRecentSave = saveFile;
                }
            }
    
            if (mostRecentSave != null)
            {
                SaveSystem.LoadGame (mostRecentSave);
            }
        }
    
    }
    

    To use, attach to a prefab and use the Object: Call event Action to invoke its ContinueGame function.

  • This gives me error CS1503: Argument 1: cannot convert from 'AC.SaveFile' to 'int'...

  • May be an issue with your AC version.

    Try this:

    using UnityEngine;
    using AC;
    
    public class CustomContinueGame : MonoBehaviour
    {
    
        public void ContinueGame ()
        {
            KickStarter.saveSystem.GatherSaveFiles ();
            int maxTime = 0;
            int mostRecentSaveID = -1;
    
            foreach (SaveFile saveFile in KickStarter.saveSystem.foundSaveFiles)
            {
                var time = -saveFile.updatedTime;
                if (time > maxTime)
                {
                    maxTime = time;
                    mostRecentSaveID = saveFile.saveID;
                }
            }
    
            if (mostRecentSaveID >= 0)
            {
                SaveSystem.LoadGame (mostRecentSaveID);
            }
        }
    
    }
    
  • This got rid of the error. But still not working quite right, it seems to ignore autosaves and only load the most recent manual save, whereas save>continue from last save will load autosave if it is the newest...

  • I added a debug log and it seems the autosave update time is always 0...

  • This behaviour will likely be changed in the next update, but for an older release you can open up SaveFileHandler_SystemFile (or whichever file handler script you're using), and remove the isAutoSave check from the GetSaveFile function:

    if (!isAutoSave)
    {
        System.TimeSpan t = fileInfo.LastWriteTime - new System.DateTime (2015, 1, 1);
        updateTime = (int) t.TotalSeconds;
    }
    
  • Mine looks slightly different, but I did this - https://www.dropbox.com/scl/fi/tpz0vbuhcaegrusqbxvl8/Screenshot-2024-10-15-103258.png?rlkey=bxv6afcrzgefpujujyfigsznu&dl=0
    But now nothing loads and the log says all saves have update time 0...

  • Wait, I misunderstood and removed the whole thing o:) Just removing the check fixed this issue.

    All working as intended now, thanks Chris! x

  • Separate, related question: How are the save labels stored? It seems my save data is synching with Steam cloud, but the Time/date on the save label does not... Any idea why his would be or how to fix it?

  • Save file label data is stored within the Profile, i.e. the Options Data, so that it can be extracted without having to load the save file itself.

    If you don't have access to this, you can override the SaveFile's label based on its GetUpdatedTime function, formatted to your intent.

    Something along these lines, set to rewrite save labels when the Save menu is turned on:

    using UnityEngine;
    using AC;
    
    public class OverrideSaveLabels : MonoBehaviour
    {
    
        void OnEnable () { EventManager.OnMenuTurnOn += OnMenuTurnOn; }
    
        void OnMenuTurnOn (Menu _menu, bool isInstant)
        {
            if (_menu.title != "Save") return;
    
            foreach (var saveFile in KickStarter.saveSystem.foundSaveFiles)
            {
                var updatedTime = saveFile.GetUpdatedTime ();
                saveFile.SetLabel (updatedTime.ToShortDateString () + " " + updatedTime.ToShortTimeString ());
            }
        }
    
    }
    
  • This gives me:

    error CS1061: 'SaveFile' does not contain a definition for 'GetUpdatedTime' and no accessible extension method 'GetUpdatedTime' accepting a first argument of type 'SaveFile' could be found (are you missing a using directive or an assembly reference?)

  • Looks like it's down to the older version you're using.

    Try copy/pasting this into your SaveFile script:

    public DateTime GetUpdatedTime ()
    {
        int newTime = 200000000 - updatedTime;
        TimeSpan ts = new TimeSpan (0, 0, newTime);
        DateTime old = new DateTime (2015, 1, 1);
        return old.Add (ts);
    }
    
  • edited October 2024

    Like this?

    https://www.dropbox.com/scl/fi/x5dybeepyqckbp9l4wovn/Screenshot-2024-10-18-131955.png?rlkey=cbgt4egoiwj6qf9kn45gzj8ob&st=1wfqemqr&dl=0

    That gave me this error:

    Assets\AdventureCreator\Scripts\Save system\FileHandling\SaveFile.cs(117,10): error CS0246: The type or namespace name 'DateTime' could not be found (are you missing a using directive or an assembly reference?)

  • Add using System; to the top of the 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.