Need help with saving system

So, i’m making a game where the player moves through predetermined rooms, can pick up items and use items. There is also dialogue, but that is not the issue. The issue is that i’m making a save system to save things such as: active item, doors that have been opened, enemies inside the different rooms, dialogue cleared, positions and rotations etc.

So the approach I took was to make a binary saving system.
The system I took inspiration from was the one shown in this video:

(He shows the reference and the subclass at 3:40)

But the problem is that i’m trying to replicate his idea of subclasses to store different types of data, but the way he shows it, only shows the first part of it. Not how you actually get ahold of the subclasses data. The way he shows it will always return the reference and all it’s data as null.

How do I actually get ahold of solid references to the subclasses?

I haven’t created a saving system but here’s an idea: You could create a SaveGame() class like this:

public bool door1;
public bool door2;
//...

Save(int ID bool status)
{
     switch(ID)
     {
          case 1://door1
          {
               door1 = status;
               break;
          }
     }
}

And each door could have a class like this:

public int ID;
public bool status;//true = open
public SaveGame savegame;

OpenDoor()
{
     status = true;
     savegame.Save(ID, status);
}

This would save the door status as soon as they open it. Just food for thought.

1 Like

Thanks for the idea! I managed to implement it into my binary saving system with a get;set; for every different subclass i wanted to save info for. So this thread is therefore closed and solved!

Edit: Here is the subclass for the doors as well as the initializer.

[System.Serializable]
public class DoorData
{
    public int ID;
    public bool isOpen;
}
    private List<DoorData> _doors;
    public List<DoorData> Doors
    {
        get
        {
            if (_doors == null)
            {
                _doors = new List<DoorData>();
            }

            return _doors;
        }
        set
        {
            _doors = value;
        }
    }
1 Like