Circular References

Easy Save 2 has been replaced by Easy Save 3, so is no longer supported.
Locked
Frank
Posts: 5
Joined: Wed Mar 08, 2017 7:54 pm

Circular References

Post 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?
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Circular References

Post 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
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Frank
Posts: 5
Joined: Wed Mar 08, 2017 7:54 pm

Re: Circular References

Post 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?
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Circular References

Post 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
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
jeffsim
Posts: 9
Joined: Tue Jul 23, 2019 2:02 pm

Re: Circular References

Post 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
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Circular References

Post 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
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Locked