Autosave

m633games

New member
Hi,
I'm trying to setup autosave for a mobile game using the instructions at https://opsive.com/support/documentation/ultimate-inventory-system/save-system but it doesn't seem to work (it works if I use the manual way with the Save/Load menu button). Is it as simple as setting those the values below to true on the following scripts in the Game object?

Save System Manager script:
Auto Load on Initialize
Auto Load on Scene load
Auto Save on Scene load
Auto save on application quit

Inventory System Manager Item Saver script:
Save on destroy
Save on application quit

Thanks!
 
Although those options are available it is more then often better to save and load manually. The main reason is the script execution order. Saving on destroy can sometimes miss some objects because they are destroyed before the InventorySystemManager. Same with loading, sometime you load before or after the objects to load are spawned (usually less of an issue since the system should be able to load correctly).

I highly recommend you write your own code to choose when to save and load. This way you can save before starting the scene change, or before the application starts to quit. You'll have more control, and it will be easier to hide the save and load times within loading screens.

Note that our save system is focused on the Inventory, it was designed to be easily integrated to other more generic save systems (that's if you plan on saving other things that are not related to the inventory).
 
Thanks for the clarification Sangemdoko. My apologies for the very basic question, I'm trying to do what is described at https://opsive.com/support/documentation/ultimate-inventory-system/save-system on how to save/load manually in the section "NEST OUR SAVE SYSTEM IN A THIRD PARTY SAVE SYSTEM" and I'm getting this error: "The name 'SaveSystemManager' does not exist in the current context". How do I import the SaveSystemManager inside another script so I can use it? I tried the integration package from Pixel Crushers, UCC,UIS and I'm getting all kind of errors which I don't understand so I though this would be easier if I just try to put the few lines of code inside my existing saver that works well for non-inventory stuff.

Code:
using System;
using UnityEngine;

namespace PixelCrushers
{
    public class SaverTemplate : Saver
    {
        public int saveSlot = 0;
 
        [Serializable]
        public class Data
        {
            public bool someData;
            public bool[] missionsCompleted;
        }

        public override string RecordData()
        {
            Data data = new Data();
            data.someData = false;
            Debug.Log("Saving to disk...");

            SaveSystemManager.Save(saveSlot, false);
            var saveDataInfo = SaveSystemManager.GetCurrentSaveDataInfo();
            var saveData = saveDataInfo.Data;

            return SaveSystem.Serialize(data);

            return string.Empty;
        }

        public override void ApplyData(string s)
        {
            if (string.IsNullOrEmpty(s)) return; // No data to apply.
            Data data = SaveSystem.Deserialize<Data>(s);
            if (data == null) return; // Serialized string isn't valid.
            var saveData = data as SaveData;       
           // Load the save data in a specific slot, by specifying the save data we don't need to read from disk.
            SaveSystemManager.Load(saveSlot, saveData);
            Debug.Log("Loaded data from disk...");       
        }
    }

}
 
Last edited by a moderator:
Our code is grouped in an Assembly Definition. You must add an Assembly Definition for your own scripts and then use it to reference the dependencies such as Opsive, and other packages.
There are a lot of tutorials on Assembly Definitions online:
 
Thanks! What do I need to import in my script to be able to use the code listed in your documentation? Attached is a picture of the assembly and code that I have used but I'm getting "error CS0103: The name 'SaveSystemManager' does not exist in the current context". Looking forward to the Adventure Kit :)

using System;
using UnityEngine;

public class LovedInventorySaver
{

public void RecordData()
{
// Save in file 0
SaveSystemManager.Save(0);
}
}
 

Attachments

  • Screenshot 2022-02-28 191505.png
    Screenshot 2022-02-28 191505.png
    97 KB · Views: 5
Once you have an assembly referencing our assemblies, make sure your script is part of that assembly (in the same folder or in a child folder)
Then simply let your IDE (example Visual Studio) autocomplete the using namespace. There is a shortcut to do this normally I believe it is Ctrl+'.' or Ctrl + 'Enter'

(I use another program called Rider which has different shortcuts)
 
For some reason just adding "using Opsive.UltimateInventorySystem.SaveSystem;" to the PixelCrushers saver without having to use Assemblies made it work. Thanks for the tips thought!
 
Top