Page 1 of 1

Circular References

Posted: Wed Mar 08, 2017 8:00 pm
by Frank
Hi! I just got Easy Save 2 and on the surface I like the elegance and simplicity, but I have a problem.

Some of my code is structured as follows:

Class Scheduler has two Dictionary Lists, locations and units.

Location is a list of 'Location' Objects, units is a list of 'Unit' Objects.

Each location object has, in turn, a list of 'unit' objects.

Each 'unit' object has a reference to the current location it is attached to.

This is necessary for the way I structured my game logic, but the ES2 serialization yields a stack overflow when trying to serialize the locationlist, because it's endlessly referencing >location>unit>location>unit>location>unit etc. Most serializers I've worked with in the past had built-in support for detecting circular references. Does ES2? Am I doing something wrong here, or do I really need to spend days restructuring everything?

Re: Circular References

Posted: Wed Mar 08, 2017 8:20 pm
by Joel
Hi there,

Easy Save does not detect cyclic references because there is a very significant overhead of doing this at runtime. Unity's own editor serialiser doesn't actually allow cyclic references either (though it does detect them), and instead they suggest that you create an array of references to your objects and store indices into this instead.

This is the first time we've had this requested, so I've added a feature request which you can vote on here: http://moodkie.com/forum/viewtopic.php?f=11&t=1137

Also note that Easy Save 3 (which will be a free update to existing users and hopefully be entering beta soon) will store data by reference by default, making circular references a non-issue.

All the best,
Joel

Re: Circular References

Posted: Wed Mar 08, 2017 10:24 pm
by Frank
Joel wrote:Hi there,

Easy Save does not detect cyclic references because there is a very significant overhead of doing this at runtime. Unity's own editor serialiser doesn't actually allow cyclic references either (though it does detect them), and instead they suggest that you create an array of references to your objects and store indices into this instead.

This is the first time we've had this requested, so I've added a feature request which you can vote on here: http://moodkie.com/forum/viewtopic.php?f=11&t=1137

Also note that Easy Save 3 (which will be a free update to existing users and hopefully be entering beta soon) will store data by reference by default, making circular references a non-issue.

All the best,
Joel
Ah, thanks for the response! I know the Unity editor doesn't allow them, but I'm using a singleton to handle those objects so that's not a problem.

Storing an array of references would be far from ideal, but if there's no other way... Easy Save 3 sounds good. Any estimates on the ETA? Soon as in weeks, or soon as in months?

Re: Circular References

Posted: Thu Mar 09, 2017 7:52 am
by Joel
We're hoping the beta for Easy Save 3 will be available in a few weeks. Also I should note that there will be one caveat regarding saving references, at least upon release anyway: any object you want to save a reference to must inherit from must be a UnityEngine.Object (i.e. MonoBehaviour, ScriptableObject).

All the best,
Joel

Re: Circular References

Posted: Fri Jul 26, 2019 5:30 pm
by jeffsim
Apologies for necro'ing an old thread, but I can't find the answer elsewhere -

> there will be one caveat regarding saving references, at least upon release anyway: any object you want to save a reference to must inherit from must be a UnityEngine.Object (i.e. MonoBehaviour, ScriptableObject).

Is that caveat still a requirement, or is storing non-UnityEngine Objects by reference supported?

Thanks
Jeff

Re: Circular References

Posted: Sat Jul 27, 2019 9:25 am
by Joel
Hi Jeff,

It's only possible to store UnityEngine.Objects by reference because it's not possible to maintain a persistent reference to a System.Object between editor, build and runtime.

However, you may be able to maintain your own reference IDs for your System.Objects and modify the ES3Type for your classes so that it stores this reference ID, and upon loading uses this reference ID to find your specific System.Object.

All the best,
Joel