Saving references to types in game with a complex save state

Discussion and help for Easy Save 3
Post Reply
bzwill
Posts: 7
Joined: Mon May 14, 2018 8:58 pm

Saving references to types in game with a complex save state

Post by bzwill »

Hello,

I'm making a tycoon style game, and various objects currently save lists which reference people, etc, sometimes via a particular component or interface type.

In order to save these references, I am looking for help for a best practice pattern. I have a few questions:

[*] I need to be able to use lists which either reference a component type (like Person) or an interface like (IHasInventory) etc. so Ideally i'd like a solution for all fits.
[*] Assuming I need to use a unique reference system, I assume I need to do some post - load work to relink things - if so whats the best way?
[*] Should I be starting this project with ES2 or ES3!? :)

I've looked through the documentation, but I can't seem to find a long guide which goes into detail about how to save a complex save state such as this - If there's already something that exists, please point me to it :)

Thanks!
User avatar
Joel
Moodkie Staff
Posts: 4846
Joined: Wed Nov 07, 2012 10:32 pm

Re: Saving references to types in game with a complex save s

Post by Joel »

Hi there,

In Easy Save 3, Component types will be saved by reference and by value, so you can simply do:
ES3.Save<List<Person>("personList", personList);
var personList = ES3.Load<List<Person>("personList");
Unfortunately saving interfaces is not currently possible, so you would need to save Lists of the concrete type instead. As this is the first time it has been requested, I have added a Feature Request for interface support here.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
bzwill
Posts: 7
Joined: Mon May 14, 2018 8:58 pm

Re: Saving references to types in game with a complex save s

Post by bzwill »

Hey Joel,

Thanks for the reply, and that's good to know about interfaces now! :)

Can I just clarify that I understand correctly:

I have three GameObject instantiated at runtime from Prefabs called 'Person', with a MonoBehavior on them called Person. These three Persons are employed at a Building (With a monobehaviour Building) which maintains a List<Person> employees;

I need ES3 to save the three gameobjects of Person, and the Building gameobject with its list.

When I reload, the three Persons and the building with be instantiated and the Building will still have a List<Person> that references the three gameobjects Person behaviours?

Thanks
User avatar
Joel
Moodkie Staff
Posts: 4846
Joined: Wed Nov 07, 2012 10:32 pm

Re: Saving references to types in game with a complex save s

Post by Joel »

Hi there,

In this case you would need to follow the Saving Prefabs guide to save your prefab instances: https://docs.moodkie.com/easy-save-3/es ... s-prefabs/

Then you would need to add support for your Person MonoBehaviour in Window > Easy Save 3 > Types (see https://docs.moodkie.com/easy-save-3/es ... -es3types/) so that it knows to save the Person Component.

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