ES2 instantiates new objects into empty List on load

Discussion and help for Easy Save 3
Post Reply
Nerrolken
Posts: 2
Joined: Tue Sep 12, 2017 10:21 pm

ES2 instantiates new objects into empty List on load

Post by Nerrolken »

I'm an Easy Save newbie, and I'm trying to get it up and running in my game. I'm saving single values perfectly, so now I'm trying to save my more complex game data. Everything seems to be working, except that it seems to be erroneously instantiating custom-class objects into a List that was empty at time of saving.

Background: I've got a GNGame class, which includes (among other properties) a List of GNCity objects, each of which includes (among other properties) a List of GNFacility objects. All three are custom object classes (not Monobehaviours, for a number of reasons), and all three have been registered with ES2, with their own "ES2UserType_" files.

I can save the GNGame class and I get no errors. (Note: I am saving it without any GNCity objects. The List has been instantiated, but it's empty, and I've confirmed that repeatedly. And of course, no GNCity objects means no GNFacility objects either.)

When I try to load it again, it goes through a bunch of properties in the GNGame object (bools and strings and ints and even another List of custom classes) and everything works fine, until it gets to that List of GNCity objects. When it hits that line, it suddenly starts instantiating GNCity objects and then instantiating GNFacility objects within them, all using the "ES2UserType_" classes as though they were being loaded from the save. These objects have no data (all ints are 0, etc), and after a few iterations it hits a crash. For example right now I'm getting an "ArgumentOutOfRangeException" on a DateTime property in the 4th GNFacility object, but I've gotten other crashes too. I tried commenting out all of the "Read" calls in the GNFacility class and Unity froze entirely, which I have to assume is from an infinite loop of new empty GNFacility objects being "loaded".

I have scoured my code for anything that could be instantiating cities and facilities on load, and I can't find anything. Plus, it's happening in the "ES2UserType_" classes, so it seems like it's not something I'm doing but rather a problem with the load. I know that these kinds of bugs usually come down to user error, though, so I'll definitely keep looking, but I just wanted to swing by here and see if anyone had any ideas for what could be happening.

Has anyone experienced anything similar?
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: ES2 instantiates new objects into empty List on load

Post by Joel »

Hi there,

I've never heard of anything like this happening before.

Would you be able to create a very basic test project which replicates the error and PM me the link and instructions to replicate it?

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Nerrolken
Posts: 2
Joined: Tue Sep 12, 2017 10:21 pm

Re: ES2 instantiates new objects into empty List on load

Post by Nerrolken »

Turns out after a LOT of experimentation, it was the result of having an unequal number of "Write" and "Read" calls in the "ES2UserType_" file. I didn't want to save certain fields under certain circumstances, so I'd made some of the "Write" lines conditional, trusting that the later "Read" lines would return NULL on load if there was no data. Instead, it threw off the load process, so the data for later fields got messed up. Ensuring that the Read calls weren't made for fields that hadn't had Write called solved the problem.
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: ES2 instantiates new objects into empty List on load

Post by Joel »

Glad you managed to find the solution to your problem!

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