Here's the first error I'm encountering. I'm just going to go into too much detail so you can see what I'm attempting to accomplish: I start by saving some default settings about my game if there isn't a settings file, things like resolution, windowed mode, quality of shadows, etc.
So I call
ES3.Save<Settings>("Settings", this)from my settings monobehaviour.
Here's my Settings ES3Type (still called ES2UserType_Settings because I'm migrating):
namespace ES3Types { public class ES2UserType_Settings : ES3Type { public override void Write(object obj, ES3Writer writer) { Settings data = (Settings)obj; // Add your writer.Write calls here. data.SaveData(writer); } public override object Read<T>(ES3Reader reader) { Settings data = Settings.Instantiate(); ReadInto<T>(reader, data); return data; } public override void ReadInto<T>(ES3Reader reader, object c) { Settings data = (Settings)c; // Add your reader.Read calls here to read the data into the object. data.LoadData(reader); } } }My settings monobehaviour has SaveData and ReadData, and these look like:
public void SaveData(ES3Writer writer) { writer.Write(seenFirstSplash); writer.Write(soundEffectsVolume); writer.Write(musicVolume); writer.Write(currentLanguage); writer.Write(subtitles); writer.Write(currentAnimationQuality); writer.Write(fullscreen); writer.Write(resolutionWidth); writer.Write(resolutionHeight); writer.Write(currentShadowQuality); writer.Write(currentVSync); writer.Write(currentUIScale); } public void LoadData(ES3Reader reader) { seenFirstSplash = reader.Read<bool>(); soundEffectsVolume = reader.Read<float>(); musicVolume = reader.Read<float>(); SetCurrentLanguage(reader.Read<Languages>()); subtitles = reader.Read<bool>(); currentAnimationQuality = reader.Read<AnimationQualities>(); fullscreen = reader.Read<bool>(); resolutionWidth = reader.Read<int>(); resolutionHeight = reader.Read<int>(); currentShadowQuality = reader.Read<ShadowQualities>(); currentVSync = reader.Read<int>(); currentUIScale = reader.Read<float>(); SetupValues(); // Goes and applies all these values to the parts of the game that need them. }Exciting stuff. Just a bunch of ES3Reader/ES3Writer calls. Previously this was all ES2Reader/ES3Writer, and was working alright.
But when I try and run the game, this is the stacktrace of the error I get:
Code: Select all
ArgumentNullException: Value cannot be null.
Parameter name: key
System.Collections.Generic.Dictionary`2[TKey,TValue].TryInsert (TKey key, TValue value, System.Collections.Generic.InsertionBehavior behavior) (at <e1a80661d61443feb3dbdaac88eeb776>:0)
System.Collections.Generic.Dictionary`2[TKey,TValue].set_Item (TKey key, TValue value) (at <e1a80661d61443feb3dbdaac88eeb776>:0)
ES3Internal.ES3TypeMgr.Init () (at Assets/Plugins/Easy Save 3/Scripts/Types/ES3TypeMgr.cs:124)
ES3Internal.ES3TypeMgr.GetOrCreateES3Type (System.Type type, System.Boolean throwException) (at Assets/Plugins/Easy Save 3/Scripts/Types/ES3TypeMgr.cs:17)
ES3Writer.Write (System.Object value, ES3+ReferenceMode memberReferenceMode) (at Assets/Plugins/Easy Save 3/Scripts/Writers/ES3Writer.cs:128)
ES3Internal.ES3JSONWriter.StartWriteProperty (System.String name) (at Assets/Plugins/Easy Save 3/Scripts/Writers/ES3JSONWriter.cs:126)
ES3Writer.Write[T] (System.String key, System.Object value) (at Assets/Plugins/Easy Save 3/Scripts/Writers/ES3Writer.cs:84)
ES3.Save[T] (System.String key, System.Object value) (at Assets/Plugins/Easy Save 3/Scripts/ES3.cs:27)
Settings.SaveSettings () (at Assets/Scripts/Game/Meta/Settings.cs:165)
Settings.SetResolution (UnityEngine.Resolution newResolution) (at Assets/Scripts/Game/Meta/Settings.cs:287)
Settings.SetupValues () (at Assets/Scripts/Game/Meta/Settings.cs:228)
Settings.SetDefaults () (at Assets/Scripts/Game/Meta/Settings.cs:190)
Settings.LoadSettings () (at Assets/Scripts/Game/Meta/Settings.cs:171)
Settings.Awake () (at Assets/Scripts/Game/Meta/Settings.cs:198)
internal static void Init() { var typeList = ES3Reflection.GetInstances<ES3Type>(); types = new Dictionary<Type, ES3Type>(typeList.Count); for(int i=0; i<typeList.Count; i++) types[typeList.type] = typeList; // Check that the type list was initialised correctly. if(types == null || types.Count == 0) throw new TypeLoadException("Type list could not be initialised. Please contact Easy Save developers on mail@moodkie.com."); }
The thing I'm missing is how ES3 knows what types associate with what ES3Type? Clearly the magic is tripping up here because I'm not using the ES3 Custom Type creator from the Ease Save 3 window in Unity, I'm instead migrating my old types to the new ones. In ES2 I'd add a line in the ES2Type list and it was all explicitly defined there, what associates with what, but clearly there's a new way of doing things here.
When I type "settings" in the Easy Save 3 window, it doesn't appear. If I type a single letter and scroll down the enormous list of types till I do see Settings, and click on it, I get this error in the editor:
Code: Select all
TypeLoadException: ES3Type for primitive could not be found, and the type list is empty. Please contact Easy Save developers at http://www.moodkie.com/contact
ES3Internal.ES3TypeMgr.CreateES3Type (System.Type type, System.Boolean throwException) (at Assets/Plugins/Easy Save 3/Scripts/Types/ES3TypeMgr.cs:86)
ES3Internal.ES3TypeMgr.GetOrCreateES3Type (System.Type type, System.Boolean throwException) (at Assets/Plugins/Easy Save 3/Scripts/Types/ES3TypeMgr.cs:23)
ES3Types.ES3DictionaryType..ctor (System.Type type) (at Assets/Plugins/Easy Save 3/Scripts/Types/Collection Types/ES3DictionaryType.cs:20)
ES3Internal.ES3TypeMgr.CreateES3Type (System.Type type, System.Boolean throwException) (at Assets/Plugins/Easy Save 3/Scripts/Types/ES3TypeMgr.cs:71)
ES3Internal.ES3TypeMgr.GetOrCreateES3Type (System.Type type, System.Boolean throwException) (at Assets/Plugins/Easy Save 3/Scripts/Types/ES3TypeMgr.cs:23)
ES3Internal.ES3Reflection.TypeIsSerializable (System.Type type) (at Assets/Plugins/Easy Save 3/Scripts/ES3Reflection.cs:178)
ES3Internal.ES3Reflection.GetSerializableFields (System.Type type, System.Boolean safe, System.String[] memberNames) (at Assets/Plugins/Easy Save 3/Scripts/ES3Reflection.cs:90)
The most helpful thing would be to have an outline as to what my ES2UserType_Settings ES3Type should actually look like - I'm sure the Types panel in the Easy Save 3 window could help me there, but as discussed above, I'm having errors there too.