Single Save

This page shows how to save your game when you are using a single save file to save the progress of your game.

Marking items to be saved

Marking simple items to be saved can be very easily done by adding the Saved attribute to a property. Safeguard currently only supports properties.

public class MyBehaviour : MonoBehaviour
{
    [Saved]
    public string PropertyToSave { get; set; }
}

This is the easiest and most common way to save values for an object in your game. It is important to note that the path towards your script component should be unique. This means that your scene hierarchy can not contain duplicate GameObjects with the same name at the same level in the hierarchy. This method also does not support objects created at runtime. This meaning that if u have a manager class that keeps track of multiple GameObjects the saving should happen on the manager class, and the manager class should re-instantiate these objects. For this you can use this structure as reference.

[Saved]
public List<string> SavedIds
{
    get
    {
        // Return the values you want to save
        return moduleData.Select(x=> x.MyId).ToList();
    }
    set
    {
        //Actually do something usefull with your saved data here
        foreach (var id in value) new GameObject("");
    }
}

public List<MyClass> SavedObjects { get; private set; } = new();

Save the game

SaveSystem.Save(SaveType.Quick, "SceneName");

Load the game

If you want to load the latest save

SaveSystem.LoadLatestSave();

This page was last edited on 2024-03-09 11:45

Powered by Wiki|Docs

This page was last edited on 2024-03-09 11:45

BiteMe Games
2024

Powered by Wiki|Docs