Error when loading save file (Scriptable Objects? )

Discussion and help for Easy Save 3
Post Reply
Passero
Posts: 10
Joined: Mon Oct 07, 2019 12:05 pm

Error when loading save file (Scriptable Objects? )

Post by Passero »

I finally refactored my code and the saving does seem to work. No more cyclic references anymore :)

The saving does work but now I have an error when I load the data, Here's the full stack:

I assume it has something to do with ScriptableObjects? I have plenty of those in my components as references.

I am wondering... I call the Load method in the Awake method of an object. Is it possible that not all gameObjects have been processed and therefore some SO's are not yet fully loaded into the scene, hence the error?
If so, what should I do to overcome this? I rely on the GameManager to be run first as all other objects depend on it so I can't really delay this call until later...

Code: Select all

NullReferenceException: Object reference not set to an instance of an object
ES3Types.ES3ScriptableObjectType.ReadUnityObject[T] (ES3Reader reader) (at Assets/Plugins/Easy Save 3/Scripts/Types/ES3ScriptableObjectType.cs:56)
ES3Types.ES3UnityObjectType.ReadObject[T] (ES3Reader reader) (at Assets/Plugins/Easy Save 3/Scripts/Types/ES3UnityObjectType.cs:55)
ES3Types.ES3ObjectType.Read[T] (ES3Reader reader) (at Assets/Plugins/Easy Save 3/Scripts/Types/ES3ObjectType.cs:41)
ES3Reader.ReadObject[T] (ES3Types.ES3Type type) (at Assets/Plugins/Easy Save 3/Scripts/Readers/ES3Reader.cs:215)
ES3Reader.Read[T] (ES3Types.ES3Type type) (at Assets/Plugins/Easy Save 3/Scripts/Readers/ES3Reader.cs:244)
ES3Types.ES3Type.ReadProperties (ES3Reader reader, System.Object obj) (at Assets/Plugins/Easy Save 3/Scripts/Types/ES3Type.cs:110)
ES3Types.ES3ReflectedObjectType.ReadObject[T] (ES3Reader reader) (at Assets/Plugins/Easy Save 3/Scripts/Types/Reflected Types/ES3ReflectedObjectType.cs:26)
ES3Types.ES3ObjectType.Read[T] (ES3Reader reader) (at Assets/Plugins/Easy Save 3/Scripts/Types/ES3ObjectType.cs:41)
ES3Reader.ReadObject[T] (ES3Types.ES3Type type) (at Assets/Plugins/Easy Save 3/Scripts/Readers/ES3Reader.cs:215)
ES3Reader.Read[T] (ES3Types.ES3Type type) (at Assets/Plugins/Easy Save 3/Scripts/Readers/ES3Reader.cs:244)
ES3Types.ES3ListType.Read (ES3Reader reader) (at Assets/Plugins/Easy Save 3/Scripts/Types/Collection Types/ES3ListType.cs:62)
ES3Types.ES3Type.ReadProperties (ES3Reader reader, System.Object obj) (at Assets/Plugins/Easy Save 3/Scripts/Types/ES3Type.cs:107)
ES3Types.ES3ReflectedObjectType.ReadObject[T] (ES3Reader reader) (at Assets/Plugins/Easy Save 3/Scripts/Types/Reflected Types/ES3ReflectedObjectType.cs:26)
ES3Types.ES3ObjectType.Read[T] (ES3Reader reader) (at Assets/Plugins/Easy Save 3/Scripts/Types/ES3ObjectType.cs:41)
ES3Reader.ReadObject[T] (ES3Types.ES3Type type) (at Assets/Plugins/Easy Save 3/Scripts/Readers/ES3Reader.cs:215)
ES3Reader.Read[T] (ES3Types.ES3Type type) (at Assets/Plugins/Easy Save 3/Scripts/Readers/ES3Reader.cs:244)
ES3Reader.Read[T] (System.String key) (at Assets/Plugins/Easy Save 3/Scripts/Readers/ES3Reader.cs:162)
ES3.Load[T] (System.String key, ES3Settings settings) (at Assets/Plugins/Easy Save 3/Scripts/ES3.cs:269)
ES3.Load[T] (System.String key) (at Assets/Plugins/Easy Save 3/Scripts/ES3.cs:240)

Passero
Posts: 10
Joined: Mon Oct 07, 2019 12:05 pm

Re: Error when loading save file (Scriptable Objects? )

Post by Passero »

Not sure if it has something to do with it, but I have a class like this:

Code: Select all

[System.Serializable]
public class ItemPreference
{
    public Item item;
    [Tooltip("Rate for item per day per population")]
    public float ratePerPopPerDay;
    [Tooltip("Priority of the need of the population. Will reflect on the price and when orders will be written out")]
    [Range(0,10)]
    public float needRate;
}
Item is the ScriptableObject here.
In the save file I notice it isn't saved as a SO reference but instead it serialized the entire SO:

Code: Select all

{"item":{"key":"WATER","description":"Water","icon":{"texture":{"width":256,"height":256,"format":12,"mipmapCount":1,"filterMode":1,"anisoLevel":1,"wrapMode":1,"mipMapBias":0,"rawTextureData":"\/9xpSwAFUAAAAAAAqqqqqv\/tSQIAAAAAAAAAAKqqqqr\/7UkCAAAAAAAAAACqqqqq\/+1JAgAAAAAAAAAAqqqqqv\/tSQIAAAAAAAAAAKqqqqr\/7UkCAAAAAAAAAACqqqqq\/+1JAgAAAAAAAAAAqqqqqv\/tSQIAAAAAAAAAAKqqqqr\/7UkCAAAAAAAAAACqqqqq\/+1JAgAAAAAAAAAAqqqqqv\/tSQIAAAAAAAAAAKqqqqr\/7UkCAAAAAAAAAACqqqqq\/+1JA.....

Passero
Posts: 10
Joined: Mon Oct 07, 2019 12:05 pm

Re: Error when loading save file (Scriptable Objects? )

Post by Passero »

Been doing some more digging and I definitely think it's something to do with those SOs.

When I let him create an ES3Type from the ItemPreferences I notice he does create a reference:

Code: Select all

writer.WritePropertyByRef("item", instance.item);
But when I do save, he doesn't populate the reference. Here's the part from the save file

Code: Select all

 "consumes": [{
                    "item": {},
                    "ratePerPopPerDay": 0.5,
                    "needRate": 5
                }
            ],
I double checked and in the editor, there is a reference to a scriptable object so something's gone wrong here

User avatar
Joel
Moodkie Staff
Posts: 3526
Joined: Wed Nov 07, 2012 10:32 pm

Re: Error when loading save file (Scriptable Objects? )

Post by Joel »

Hi there,

Would it be possible for you to PM me a basic project to replicate this? It's not going to be possible for me to tell what is happening from what you've said, but a repro project should allow me to see immediately what is happening.

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

Passero
Posts: 10
Joined: Mon Oct 07, 2019 12:05 pm

Re: Error when loading save file (Scriptable Objects? )

Post by Passero »

will see if I can copy/paste the classes in a new project so I can replicate it...

Passero
Posts: 10
Joined: Mon Oct 07, 2019 12:05 pm

Re: Error when loading save file (Scriptable Objects? )

Post by Passero »

ok so when I'm copying everything to a new project, it seems to work. It stores my SOs with an _ESReference.
It's the same SO, same Script as I copied it from one project to another...

Is there something I can try to troubleshoot this as I obviously can't upload a project to replicate it...


Some more info...
When I remove all generated ES3Types_* so it should use all the default behavior, then it serializes my scriptable objects and stores it in the save file which makes the save file huge and also unable to de-serialize upon loading.

When I create an ES3Type, it shows up as a byRef but it leaves it empty.

So something is causing this behavior but I don't have a clue what...

Passero
Posts: 10
Joined: Mon Oct 07, 2019 12:05 pm

Re: Error when loading save file (Scriptable Objects? )

Post by Passero »

ok I started debugging in the ES3 code to find the problem and I found it...

Noticed the ref Mgr was null. I removed the ES3 object a while ago as I didn't started integrating with a save system back then.
Now of course, I didn't remember I needed the ES3 reference manager. I've added the script to my game manager and voila, it works...

Just a tip... maybe add a warning so people understand...
If you call WriteRef it means you want to store the reference so if the manager is null, that's not good. A warning would've been good and would have saved me a few hours of debugging ;)


It is still not working... Every time the game starts, all references have different IDs so he can't find the reference...
I added the auto save component to my game object that has the ref manager but that doesn't seem to do the trick...

Passero
Posts: 10
Joined: Mon Oct 07, 2019 12:05 pm

Re: Error when loading save file (Scriptable Objects? )

Post by Passero »

Seems to be fixed but it's weird...

Upon initial importing of the asset, ES3 added the Easy Save 3 Manager but because I didn't need it then, I removed it.
From my test project I noticed that gameObject and I created my own gameObject in the scene called ES3 and attached the same scripts (ES3 inspector info, ES3 ref mgr and auto save mgr). When testing with this, it didn't work...

Only when I enabled Auto Add Manager to Scene in the settings, a gameObject with the name Easy Save 3 Manager got created and when testing then, it does work correct.
When I renamed the gameObject, a new one is created.

This entire setup seems very weird and not easy to troubleshoot... I recommend you add a section in the getting started guide so people know it's mandatory to have a gameObject called "Easy Save 3 Manager" which is created by your framework and not a manual one because that doesn't work.

I do find it a bit annoying that I spend so much time because of this issue...
First the ref mgr was null which wasn't obvious and now this...

User avatar
Joel
Moodkie Staff
Posts: 3526
Joined: Wed Nov 07, 2012 10:32 pm

Re: Error when loading save file (Scriptable Objects? )

Post by Joel »

Hi there,

Glad you managed to find a solution to your issue, and thank you for the detailed information.

I'm currently working on changes to how referencing works, so I'll add a reference manager check which throws an error message so nobody runs into the same issues. Apologies that this delayed you to begin with, this is the first time we've encountered this issue.

If you have any other questions, please let me know.

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

Post Reply