Easy Save Type Mismatch issue

Discussion and help for Easy Save 3
Post Reply
zay_altick
Posts: 16
Joined: Sat Apr 17, 2021 11:42 am

Easy Save Type Mismatch issue

Post by zay_altick »

I'm running into an issue with saving my SO with this script specifically.

This is the script

Code: Select all

[System.Serializable]
public class CutsceneData
{
    //[SerializeField] public TimelineAsset timelineAsset;
    public bool hasBeenPlayed;


    public void SetHasBeenPlayedToTrue()
    {
        hasBeenPlayed = true;
    }
}

[CreateAssetMenu(fileName = "CutsceneSO", menuName = "ScriptableObjects/Cinematics", order = 1)]
public class CutsceneSO : ScriptableObject
{
    [SerializeField] private CutsceneData cutsceneData;

    public CutsceneData CutsceneData => cutsceneData;
    private void Awake()
    {
        hideFlags = HideFlags.DontUnloadUnusedAsset;
    }
}
I want to save the values of this in another SO I made that stores level info
Mismatch.png
Mismatch.png (166.1 KiB) Viewed 1178 times
This is the code I use to save the data

Code: Select all

    private void Save()
    {
        for (int i = 0; i < scenesData.Count; i++)
        {
            foreach (Level level in scenesData[i].levels)
            {
                ES3.Save<Level>(level.sceneName, level);
                ES3.Save<TimeRankingSO>(level.rankingSO.name + " " + TIME_TRIAL_KEY, level.rankingSO);
                ES3.Save<ScoreRankingSO>(level.scoreRankingSO.name + " " + SCORE_RANKING_KEY, level.scoreRankingSO);
                for (int j = 0; j < level.cinematicInfo.Count; j++)
                {
                    string cutsceneKey = level.cinematicInfo[j].name;
                    ES3.Save<CutsceneSO>(cutsceneKey, level.cinematicInfo[j]);
                }
            }
        }

        Debug.Log("Saved");
    }
And this is how I load

Code: Select all

    private void Load()
    {
        for (int i = 0; i < scenesData.Count; i++)
        {
            foreach (Level level in scenesData[i].levels)
            {
                Level loadedObject = ES3.Load<Level>(level.sceneName);
                TimeRankingSO timeRankingSO = loadedObject.rankingSO;
                ScoreRankingSO scoreRank = loadedObject.scoreRankingSO;

                timeRankingSO = ES3.Load<TimeRankingSO>(loadedObject.rankingSO.name + " " + TIME_TRIAL_KEY);
                scoreRank = ES3.Load<ScoreRankingSO>(loadedObject.scoreRankingSO.name + " " + SCORE_RANKING_KEY);


                for (int j = 0; j < level.cinematicInfo.Count; j++)
                {
                    string cutsceneKey = level.cinematicInfo[j].name;
                    CutsceneSO loadedCutscene = ES3.Load<CutsceneSO>(cutsceneKey);
                    level.cinematicInfo[j] = loadedCutscene;
                }
            }
        }
    }
For some reason, when I run load, it keeps giving me a type mismatch and it's ONLY with this script. I'm unsure if this is a easy save issue or SO issue, but I figured I'd ask here just in case.
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Easy Save Type Mismatch issue

Post by Joel »

Hi there,

Please can you post the full error you are getting with line numbers.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
zay_altick
Posts: 16
Joined: Sat Apr 17, 2021 11:42 am

Re: Easy Save Type Mismatch issue

Post by zay_altick »

Hey!

Update:

Something I noticed was the ES3 reference ID of the SO I'm trying to save (CutsceneSO) is printing out -1 when I do a Debug.Log within the ES3ScriptableObjectType script.


The only workaround I found is storing the Cutscene SO data before I load the Level SO which is an SO where I store a list of Cutscene SO.

I don't have an error anymore as this seemed to work, but I just found it weird that when the cutscene SO loads, it has an ES3Ref id of -1
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Easy Save Type Mismatch issue

Post by Joel »

Hi there,

This will be because the ScriptableObject is either generated at runtime (so won't have a persistent ID), or the ScriptableObject isn't a dependency of your scene (so won't be in the reference manager for that scene). In this case it's necessary to save and load it by value before saving or loading anything which references it, to ensure it's reference ID is in the manager.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
zay_altick
Posts: 16
Joined: Sat Apr 17, 2021 11:42 am

Re: Easy Save Type Mismatch issue

Post by zay_altick »

Hey!

I was doing some digging and I've heard what you're talking about a lot in regards to it either being generated at runtime or it not being a dependency.

I'm still having a bit of trouble seeing how this happened to me because there isn't anywhere in my project where I instantiate this SO during runtime. I ran a debug on the SO to test this and I never see that debug run.

On this part "ScriptableObject isn't a dependency of your scene"

The only thing I do is pass this SO as a reference in my GO that needs it. I do this so when the player collides with it, it will check to see if the data within that SO has changed.

That's why I'm confused as to what about this specific SO is so different from the others I've made.
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Easy Save Type Mismatch issue

Post by Joel »

Hi there,

If you replicate this in a new project with a simple scene and private message to me with instructions I'm happy to take a look to see exactly why this is happening in your situation.

I'd also double check that you're using the latest version of Easy Save in case you're encountering an issue from a previous version.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
zay_altick
Posts: 16
Joined: Sat Apr 17, 2021 11:42 am

Re: Easy Save Type Mismatch issue

Post by zay_altick »

Just sent a message with the specific project issue
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Easy Save Type Mismatch issue

Post by Joel »

Thanks for sending that over, much appreciated.

You're using an older version of Easy Save. Updating Easy Save and then saving your scene will resolve your issue.

Just to clarify, this is happening in the version of Easy Save you are using because there was previously a limit to the depth that the reference manager would gather references, and the ScriptableObject you're having issues with is beneath this depth, so is never added to the reference manager. Saving the SO and loading it before loading anything which references it works because it adds the SO's reference to the manager, but this isn't necessary in the latest version of Easy Save.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
zay_altick
Posts: 16
Joined: Sat Apr 17, 2021 11:42 am

Re: Easy Save Type Mismatch issue

Post by zay_altick »

Ah I see. Thanks for your help Joel!
Definitely should've looked at updating it beforehand. It's been quite a bit haha
Post Reply