Instances and references

Easy Save 2 has been replaced by Easy Save 3, so is no longer supported.
Locked
drHogan
Posts: 5
Joined: Tue Mar 28, 2017 8:55 am

Instances and references

Post by drHogan »

Hello guys,

first of all, top class asset, it's really saving me a lot of time in implementing saves in our game, Empires in Ruins.

Now the question/doubt i have. Premise is, that I didn't test yet (I am still heavily refactoring our code so to allow to save everything that is needed).

I have a list of Officers classes (already added and supported as ES2Type) general to the game, and then for example when one of them is used in a province of the game as governor, i reference it there through public Officer governor variable. What is the standard behavior of ES2 in this case when saving the list and the province. Would it create two duplicates of the Officer and then when reloaded would be two separate instances right?
If that is the case, is there an embedded way to avoid this or should I rewrite the code so that on load the officer is re-references on the province from the list?

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

Re: Instances and references

Post by Joel »

Hi there,

Easy Save 2 saves by value, not by reference, so you would indeed end up with two references. The workaround for this is instead of saving the object itself, maintain your own list of references and save/load the index of the object in this list.

Note that Easy Save 3 will support saving UnityEngine.Object references. Easy Save 3 will be a free update for existing users, and we hope to have a beta available soon.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
drHogan
Posts: 5
Joined: Tue Mar 28, 2017 8:55 am

Re: Instances and references

Post by drHogan »

Thanks for the quick answer, that will be my probable solution for now then.

Cheers,
H
Locked