class data always saved as null

Discussion and help for Easy Save 3
Post Reply
RickyP602
Posts: 5
Joined: Thu May 11, 2023 1:33 am

class data always saved as null

Post by RickyP602 »

Hello,
I have character data that i'm saving and loading using EasySave3 Autosave. I have noticed that if I instantiate a single character data it always stores my class as null. Oddly if I store an array of character datas it seems to store the originally instantiated values but never updates them. What is also odd is that EasySave3 is saving data on the class that holds the references to character data without issue. I feel like i'm doing something simple wrong but cannot for the life of me figure it out.

Here is the save file data for the individual character data:

"__type" : "OverSeer,Assembly-CSharp",
"_ES3Ref" : "4134415035312422496",
"goID" : "7123389511330114872",
"testData" : null

Here are both of my classes that are relevant here and my full save file:

https://hatebin.com/uvzamcginz
https://hatebin.com/keqsnkalvk
https://hatebin.com/ikeqpqcgpu

Any help at all would mean a great deal. Thank you for your time.
Rick
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: class data always saved as null

Post by Joel »

Hi Rick, and thanks for getting in contact.

I don't appear to be able to replicate this at my end. I tried to replicate this with the script below and Auto Save using the default Save and Load events.

I would first recommend manually triggering Auto Save using this section of the Auto Save guide:
https://docs.moodkie.com/easy-save-3/es ... -from-code

Once you've done this you can call Debug.Log immediately before the ES3AutoSaveMgr.Current.Save() call and check whether it's being saved as null because it is null. If it is null it would indicate an issue with your logic. If it's not null, please could you create a new project with a simple scene which replicates it and private message it to me with instructions.

All the best,
Joel

Code: Select all

using UnityEngine;

/* 
 * To use this test, clear your persistent data path (Tools > Easy Save 3 > Clear Persistent Data Path), 
 * enter playmode, exit playmode, and then re-enter playmode. It will output the names of the CharacterData.
 */
public class OverSeer : MonoBehaviour
{
    [SerializeField]
    public CharacterData[] characterDataList;
    public CharacterData testData;

    public void Start()
    {
        if (!ES3.FileExists())
        {
            characterDataList = new CharacterData[]
            {
                new CharacterData() { CharacterName = "char1"},
                new CharacterData() { CharacterName = "char2"},
                new CharacterData() { CharacterName = "char3"}
            };

            testData = new CharacterData() { CharacterName = "testData" };
        }
        else
        {
            foreach (var c in characterDataList)
                Debug.Log(c.CharacterName);

            Debug.Log(testData.CharacterName);
        }
    }
}

public class CharacterData
{
    [SerializeField]
    public static int startingValue = 10;
    [SerializeField]
    public bool Defend;
    [SerializeField]
    public string CharacterName;
    [SerializeField]
    public int MaxHealth;
    [SerializeField]
    public int CurrentHealth;
    [SerializeField]
    public int Strength;
    [SerializeField]
    public int Dexterity;
    [SerializeField]
    public int Constitution;
    [SerializeField]
    public int Intelligence;
    [SerializeField]
    public float ActionSpeed;

    [SerializeField]
    public float TurnMeter;
    public CharacterData()
    {
        this.Defend = false;
        this.TurnMeter = 0;
        this.Constitution = startingValue;
        this.Strength = startingValue;
        this.ActionSpeed = startingValue;
        this.CharacterName = "default";
        this.CurrentHealth = startingValue;
        this.Dexterity = startingValue;
        this.Intelligence = startingValue;
        this.MaxHealth = startingValue;
    }
}
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
RickyP602
Posts: 5
Joined: Thu May 11, 2023 1:33 am

Re: class data always saved as null

Post by RickyP602 »

I went and created a small scene with the relevant classes to give to you. Problem is when I did that... it worked.... So obviously something on my end you can't help with. Terribly sorry to waste your time. Thank you again.
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: class data always saved as null

Post by Joel »

No problem, let me know if there's anything else I can help with.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
RickyP602
Posts: 5
Joined: Thu May 11, 2023 1:33 am

Re: class data always saved as null

Post by RickyP602 »

Hey Joel,
I was wondering if you would mind just checking this little code snippet for me. I recognize and understand that your product is working as designed and as such the problem is on my end not yours. So if you do not have time to get back to me on this I will not take it personally.

However, after messing around in a sample project for a good bit and getting everything working on small scale I am still running into an issue when saving my character data class in my actual game. I am not going to post a lot or anything just a small snippet:

this is in my manager class awake function:

Code: Select all

if (!ES3.FileExists())
        {
            characterDataList = new CharacterData[4];
            for (int i = 0; i < characterDataList.Length; i++)
            {
                characterDataList[i] = new CharacterData();
                characterDataList[i].CharacterName = CHARACTER_NAMES[i];
                Skill DoubleAttack = new Skill("Double Attack", TypeOfSkill.ATTACK_SINGLE, true, 2, 1.5f);
                characterDataList[i].ListOfActiveSkills.Add(DoubleAttack);
                characterDataList[i].MaxHealth = 100;
                characterDataList[i].CurrentHealth = 100;
            }
        }
What I am seeing in my game is that THIS Data set on the awake function of my manager class that only ever gets called one time on the first load is the only data that will ever be in my ES3 save file. I can change it however I want in this awake function and it will save just fine. Any alteration made after this awake function has been called, even from the manager class itself, will not be saved. However the changes will be visible in game even though they are not saved. Also, other data in the manager class simple strings ints and bools is saved just fine so I know the save call is working.

What i'm wondering is simply if you have any advice on where to look or how to troubleshoot further?

Thanks again, hope you are well.
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: class data always saved as null

Post by Joel »

Hi there,

I can only assist with the Easy Save side, but as your FileExists call is checking whether the default file exists I would first check that Auto Save is using the default file. You can do this by going to the Auto Save window, expanding the 'Show advanced settings' foldout and checking that the 'Default file path' matches the 'Default file path' in the Tools > Easy Save 3 >Settings window.

While you have Auto Save's Advanced Settings open I'd also check that the Location is set to File. If it's not then it won't persist data to the same location that the FileExists all is looking for.

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