Scriptable object reference not saved

Discussion and help for Easy Save 3
User avatar
Joel
Moodkie Staff
Posts: 4846
Joined: Wed Nov 07, 2012 10:32 pm

Re: Scriptable object reference not saved

Post by Joel »

Hi there,

If you're using both then you should ensure that you're saving to separate files.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
funtomata
Posts: 26
Joined: Tue Feb 23, 2021 4:25 pm

Re: Scriptable object reference not saved

Post by funtomata »

Joel wrote: Wed Feb 24, 2021 1:30 pm Hi there,

If you're using both then you should ensure that you're saving to separate files.

All the best,
Joel
Oooooooh ok I see. Is it mentioned somewhere in the documentation? because that's not very clear.
I suppose what happens then is that the file gets completely overwritten by the autosave. Is there a practical reason why the default setting is to save both in the same file?
User avatar
Joel
Moodkie Staff
Posts: 4846
Joined: Wed Nov 07, 2012 10:32 pm

Re: Scriptable object reference not saved

Post by Joel »

Hi there,

Generally people use one or the other, because they're both different ways of doing the same thing (so it doesn't usually make sense to do both).

However, I should clarify, saving to the same file will only be a problem if you're saving the same thing with both methods. If this not the case at your end then it may be a different issue just relating to Auto Save.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
funtomata
Posts: 26
Joined: Tue Feb 23, 2021 4:25 pm

Re: Scriptable object reference not saved

Post by funtomata »

Well, changing the save path for the autosave seems to solve the problem though, so at leat there's that.

I'm using both because autosave is rather convenient but doesn't allow me to save/load SO's (since it only saves a reference) however I've not looked into custom types yet. I suppose it's possible to decide how a specific type is serialized by ES, in which case I could perhaps define a custom serialization for my inventory SO and make it work.

There's one thing that surprises me though. If SO's are saved as a reference, and unity instantiates a new SO at runtime as a clone of the SO asset, why does saving my List<Item> work (where Item is a SO). Surely, if my items is saved as a list of runtime references, they should not be properly loaded when I restart, as those references should be pointing to nowhere.

So why does saving a List<ScriptableObject> as a public field of my Inventory SO work, while autosaving a ScriptableObject, as a public field of my Interactable Monobehaviour doesn't work? There's something I'm not quite understanding
User avatar
Joel
Moodkie Staff
Posts: 4846
Joined: Wed Nov 07, 2012 10:32 pm

Re: Scriptable object reference not saved

Post by Joel »

So why does saving a List<ScriptableObject> as a public field of my Inventory SO work, while autosaving a ScriptableObject, as a public field of my Interactable Monobehaviour doesn't work? There's something I'm not quite understanding
Hi there,

I would need to see a basic project which replicates this to understand why this is, if you're able to send one over? Does the project you sent over exhibit this? Different ScriptableObjects work in different ways depending on how they're referenced by Unity.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
funtomata
Posts: 26
Joined: Tue Feb 23, 2021 4:25 pm

Re: Scriptable object reference not saved

Post by funtomata »

Ok I've been playing around to make the basic project and I've discovered something interesting.
If the SO is referenced by an object on the scene, it is added to the ES3 Reference manager, however if it is modified at runtime and changed to reference an object that was not referenced DIRECTLY (so event handler parameter, and collections don't count) by another object on the scene, then it's not added in the ES3 Reference manager and then it can't be properly saved. However if I add the SO manually to the reference manager it saves and loads fine.
User avatar
Joel
Moodkie Staff
Posts: 4846
Joined: Wed Nov 07, 2012 10:32 pm

Re: Scriptable object reference not saved

Post by Joel »

Hi there,

If I understand you correctly then this is expected behaviour, as there would be no way of knowing that instance would exist prior to runtime.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
funtomata
Posts: 26
Joined: Tue Feb 23, 2021 4:25 pm

Re: Scriptable object reference not saved

Post by funtomata »

Thanks a lot for your help.
It would be really nice if there was an extra chapter in the documentation talking about how to work with ScriptableObjects. I know there's a few things to say about using ScriptableObjects as anything else than static data containers, but there's definitely a lot of people (myself included) who use them in much more creative ways.
User avatar
Joel
Moodkie Staff
Posts: 4846
Joined: Wed Nov 07, 2012 10:32 pm

Re: Scriptable object reference not saved

Post by Joel »

Hi there,

If there's demand for it we'll definitely consider adding such a guide.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Berg
Posts: 1
Joined: Wed Feb 24, 2021 9:56 pm

Re: Scriptable object reference not saved

Post by Berg »

Hey!

Thanks for this thread. I'm with the same problem, for more than a week, trying to understand why my SO's is not saving properly.
Now I think get it.

@funtomata what workaround you did to work well? I have a SO PlayerData with a List<Item> and in this list has another SO ItemBase. Can I save every SO just with AutoSave?

And I'm here just to increase the SO documentation demand. :)
Post Reply