Saving large Class

Discussion and help for Easy Save 3
Post Reply
thecodehermit
Posts: 10
Joined: Wed Nov 25, 2020 8:12 pm

Saving large Class

Post by thecodehermit »

Hi, I have a list with a class type. That class also contains some other classes and they contain other data as well... I am trying to save the List with Easy Save. Here is how I save/load this data.

Code: Select all

// Saving 
ES3.Save("prefabs_Data_Backup", prefabs_Data, save_Path);

// Loading 
prefabs_Data = ES3.Load<List<Prefab_Data>>("prefabs_Data_Backup", save_Path);
Everything works fine with saving (as far as I see). But when I load I get the following error:
NullReferenceException: Object reference not set to an instance of an object
ES3Types.ES3Type_Texture2D.ReadUnityObject[T] (ES3Reader reader, System.Object obj) (at Assets/Plugins/Easy Save 3/Scripts/Types/Unity Types/ES3Type_Texture2D.cs:37)
After some investigation I found out easy save cant load the Texture2D objects properly. If I remove the images then the loading works without problems. The image is read/write enabled.
Can someone please tell me if this is a valid way of saving nested classes with lots of data ? And if there is some trick or way to fix the image issue.
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Saving large Class

Post by Joel »

Hi there,

It looks like the Texture is null because an image with that reference ID doesn't exist in the scene (for example, because it's generated or modified at runtime).

Please could you create a new, very basic project which replicates trying to save an object with this texture and private message it to me?

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
thecodehermit
Posts: 10
Joined: Wed Nov 25, 2020 8:12 pm

Re: Saving large Class

Post by thecodehermit »

Thanks for the reply. I created a new project but there it worked... So in the end it turned out the problem was that the save manager was inside a prefab. Once I put it outside the environment prefab the save/load started working. Do you have more info on how the save/load system works with Unity prefabs ? I mean is it supposed to work with them at all ? Currently I have everything on the scene in one huge prefab, but I am starting to see some problems with that approach (not including the easy save).
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Saving large Class

Post by Joel »

Hi there,

We have information on saving prefabs here:
https://docs.moodkie.com/easy-save-3/es ... s-prefabs/

With regards to whether putting your scene inside a prefab is a good idea, it depends on why you've structured your project that way :) What was your reasoning around having your scene in a prefab?

I can't say I've seen a project before which has this structure, and I would be surprised if there wasn't a more efficient way of achieving what you're trying to achieve with prefabs.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
thecodehermit
Posts: 10
Joined: Wed Nov 25, 2020 8:12 pm

Re: Saving large Class

Post by thecodehermit »

hmm the "Right-click the prefab and select Enable Easy Save for Prefab." didnt work when the prefab manager is inside a prefab. I guess it will be outside in the future then.
As for the scene prefab. I am pretty much self taught so this idea might not be optimal ... The reasoning was that I would have this big environment prefab which will contain everything the game needs: lights , nav meshes, post processing etc etc. So when I open a new scene I put that prefab there and then proceed to make the new level by adding stuff to it. I did it this way so that I would be able to modify the environment globally, rather than to have to make one little change in scene1 and then copy paste it on every single scene. Though most probably I would have to rethink this again.
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Saving large Class

Post by Joel »

Hi there,

In this case the manager will need to be outside of the prefab because it you would need to manager to load it, but it would need to have already been loaded for the manager to exist (which is a bit of a paradox :) )

It sounds like you should be including scenes additively rather than using a prefab to do this (i.e. https://docs.unity3d.com/ScriptReferenc ... itive.html). For more info I recommend asking on the Unity forums.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
thecodehermit
Posts: 10
Joined: Wed Nov 25, 2020 8:12 pm

Re: Saving large Class

Post by thecodehermit »

Aha I see. Yeah I did ask there, I think I have a better idea on how to go forward now. Thanks for the help.
Post Reply