Page 1 of 1

"Manager is required" warning from EditorWindow?

Posted: Mon Sep 26, 2022 1:37 am
by jjjj
Hi, is there a proper way to use the serializer in an EditorWindow script?

So I've got an EditorWindow which has a button, and when pressed, will run

Code: Select all

ES3.Serialize(myScriptableObject)
But this gives me the error:
InvalidOperationException: An Easy Save 3 Manager is required to load references. To add one to your scene...
I can fix it by creating a Manager in the scene that I have open, but that doesn't seem right because it makes the EditorWindow dependent on the opened scene having the Manager attached.

Is there a better way to handle this?

Re: "Manager is required" warning from EditorWindow?

Posted: Tue Sep 27, 2022 6:45 am
by Joel
Hi there,

UnityEngine.Object types (such as ScriptableObjects) are saved by reference and value. For this reason a reference manager is required, which must exist in a scene, as Easy Save is intended as a runtime serialiser, not an Editor serialiser (though some do use it as the latter).

The solution to this would be to only save value types, or save your data by value (to eliminate the need for a reference manager). The easiest way to do this is to provide an ES3Settings object as a parameter with the referenceMode and memberReferenceMode set to ES3.ReferenceMode.ByValue. I.e.

Code: Select all

var settings = new ES3Settings();
settings.referenceMode = ES3.ReferenceMode.ByValue;
settings.memberReferenceMode = ES3.ReferenceMode.ByValue;
var bytes = ES3.Serialize(ScriptableObject.CreateInstance<TestSO>(), settings);
All the best,
Joel

Re: "Manager is required" warning from EditorWindow?

Posted: Wed Sep 28, 2022 7:00 am
by jjjj
Thanks Joel, that has addressed my issues.

Is there documention for the reference and member reference mode options? Couldn't seem to find it in the doco website.

Re: "Manager is required" warning from EditorWindow?

Posted: Wed Sep 28, 2022 7:14 am
by Joel
Hi there,

We don't actively advertise these as we've found that very often it's difficult for people to understand the implications of saving by value vs by reference, even if the implications are documented. Instead we only suggest this if someone contacts us directly so that we can describe the implications to them for their specific use case if they run into issues.

All the best,
Joel

Re: "Manager is required" warning from EditorWindow?

Posted: Wed Sep 28, 2022 11:08 pm
by jjjj
No problem. Thanks for your help!