Saving Class with inheritance null

Discussion and help for Easy Save 3
Post Reply
Maple-Senpai
Posts: 7
Joined: Tue Mar 22, 2022 9:17 am

Saving Class with inheritance null

Post by Maple-Senpai »

Hi, I'm having some issues with saving.

The class

Code: Select all

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ChairManager : MonoBehaviour
{
    private List<ChairClass> _chairPositions = new List<ChairClass> { };

    public List<ChairClass> chairPositions { get { return _chairPositions; } set { _chairPositions = value; } }
    private static ChairManager _instance;
    public static ChairManager Instance { get { return _instance; } }

    private void Awake()
    {
        if (_instance != null && _instance != this)
        {
            Destroy(this.gameObject);
        }
        else
        {
            _instance = this;
        }
    }

    public class ChairClass
    {
        public Vector2Int chairPosition = new Vector2Int { };
        public bool isOccupied = false;
    }
}
What I use to save chairPositions

Code: Select all

        ES3.Save(_chairInfoKey, GameManager.Instance.ChairManager.chairPositions);
The save file

Code: Select all

	"ChairsInfo" : {
		"__type" : "System.Collections.Generic.List`1[[ChairManager+ChairClass, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]],mscorlib",
		"value" : [
			{
				"chairPosition" : {
					"x" : 6,
					"y" : -4
				},
				"isOccupied" : false
			}
		]
	},
BUT when I inherit ChairClass with TaskBase I get null on save

The new ChairClass with inheritance

Code: Select all

    public class ChairClass : TaskBase
    {
        public Vector2Int chairPosition = new Vector2Int { };
        public bool isOccupied = false;
    }
The TaskBase code

Code: Select all

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public abstract class TaskBase : MonoBehaviour
{
    public int priority = 0;
}
The save output with TaskBase inheritance

Code: Select all

	"ChairsInfo" : {
		"__type" : "System.Collections.Generic.List`1[[ChairManager+ChairClass, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]],mscorlib",
		"value" : [
			null
		]
	},
No errors or warning in the console. What am I doing wrong? Please help.
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Saving Class with inheritance null

Post by Joel »

Hi there,

I don't appear to be able to replicate this, and I've had no other reports of similar issues. Please could you create a new project with a very simple scene which replicates your issue and private message it to me with step-by-step instructions.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Maple-Senpai
Posts: 7
Joined: Tue Mar 22, 2022 9:17 am

Re: Saving Class with inheritance null

Post by Maple-Senpai »

I think I have solved the issue now by reimporting the Easy Save asset. Something probably got messed up back then. Thanks for replying.

Also while we are at it. I have a question.
Let's say I have CustomClass1 and CustomClass2. CustomClass1 is referenced in CustomClass2. Do I need to load CustomClass1 first before CustomClass2?

More over I have a scenario in my game where these two classes references each other. No matter which I load first the other one loses the reference when loading and becomes null.
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Saving Class with inheritance null

Post by Joel »

Hi there,
Let's say I have CustomClass1 and CustomClass2. CustomClass1 is referenced in CustomClass2. Do I need to load CustomClass1 first before CustomClass2?
That is correct.
More over I have a scenario in my game where these two classes references each other. No matter which I load first the other one loses the reference when loading and becomes null.
In these cases you would need to load twice: once to ensure the classes are instantiated, and then once more to load the references.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Maple-Senpai
Posts: 7
Joined: Tue Mar 22, 2022 9:17 am

Re: Saving Class with inheritance null

Post by Maple-Senpai »

Joel wrote: Tue Mar 22, 2022 4:12 pm Hi there,
Let's say I have CustomClass1 and CustomClass2. CustomClass1 is referenced in CustomClass2. Do I need to load CustomClass1 first before CustomClass2?
That is correct.
More over I have a scenario in my game where these two classes references each other. No matter which I load first the other one loses the reference when loading and becomes null.
In these cases you would need to load twice: once to ensure the classes are instantiated, and then once more to load the references.

All the best,
Joel
Hi I tried your advice by loading twice but its still not working properly.

On CustomClass1 I modify some of its values but in CustomClass2 the values of CustomClass1 is still the same as when it was loaded its like the connection between the two is now broken.

EDIT:

This is the logs. See the first log IsOccupied is now set to false (CustomClass1)
Then on CustomClass2 the isOccupied value is still set to true.
Image
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Saving Class with inheritance null

Post by Joel »

Hi there,

Please could you replicate this in a new project with a very simple scene and private message it to me with step by step instructions.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Post Reply