Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

[Released] Serializable Dictionary Lite - Now allowing custom editor for key field

Discussion in 'Assets and Asset Store' started by Rotary-Heart, Feb 19, 2018.

  1. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    798
    Great news, version 2.6.6 is now live!
     
    genaray likes this.
  2. sloid32

    sloid32

    Joined:
    Oct 4, 2015
    Posts:
    1
    Hi, thanks for all your hard work. I am trying to implement this using <string, List<string>> however I get a null reference when it goes to draw it in the inspector, presumably because the List<string> isn't initialised. How would I go about making this work?
     
  3. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    798
    You need to wrap your list with a class or structure. See section Advanced Dictionary (page 9) of the documentation.
     
  4. Alexandr-Archer

    Alexandr-Archer

    Joined:
    Jun 22, 2015
    Posts:
    1
    I have this bug and don't know how to fix it. Source is "prefabs", which is
    [Serializable]
    private class DiceDictionary : SerializableDictionaryBase<int, Dice3D> { }
    upload_2019-5-28_1-50-50.png
     
  5. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    798
    That's an odd bug since it's not pointing to any of my scripts. Can you tell me the steps to reproduce it? If needed you can send me your script(s) via pm or email.
     
  6. Jargs

    Jargs

    Joined:
    Dec 8, 2018
    Posts:
    5
    Ever since upgrading to Unity 2019, I've been getting this warning message:
    I'm running the latest versions of Unity (2019.1.4f.1) and SerializableDictonary (2.6.6). I have also tried completely removing SerializableDictionary and re-installing it.

    Any suggestions?
     
  7. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    798
    You can ignore that warning, it's going to be fixed with the new update, but that's on the editor side.
     
    Jargs likes this.
  8. Jargs

    Jargs

    Joined:
    Dec 8, 2018
    Posts:
    5
    Ok, thanks... I wondered if that was going to be the case.
     
  9. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    798
    Version 2.6.7 has been submitted to the asset store for review. This version includes:
    • Included new preferences setting for 2018.3+.
    • Fixed issue with custom drawer in keys.
     
  10. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    798
    Great news, version 2.6.7 is now live!
     
  11. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    1,394
    Excellent. I use this all the time. Can you maybe add a companion SerializableHashSet? I have a simpler one but it'd be great if the same inspector support were available for sets.
     
    Rotary-Heart likes this.
  12. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    798
    The new version 3.0 (which will be a paid version) will contain 2 new data structures added, one of them is the HashSet, alongside many huge changes to the way the data is stored and serialized. Keep an eye to this thread since it will be posted here once the version is sent for approval.

    Note that, while the new version will be a paid version, the previous 2.x version will NOT be deprecated, but it will not receive any new features.
     
  13. genowhirl9999

    genowhirl9999

    Joined:
    Jun 24, 2016
    Posts:
    11
    So I wanted to store a dictionary with a component as the key but it doesn't seem to support serializing monobehaviour derived classes? I was using a list of the same class before and it serializes fine.
     
  14. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    798
    Thanks for the report, this is the first time that anyone has tried to use a component as key so this was an unknown issue.

    There is a way to make it work, same as with generic as key you need to add it to a references Scriptable Object. The only different thing is that you will need to setup a default value on the Scriptable Object (a dummy prefab will work fine). Here's an example of what I mean:

    Here you can see the reference to a dummy prefab added to the references Scriptable Object (it's an empty game object with the script component)
    Capture.PNG

    Then when a new element is added to the dictionary it will use the dummy as the default (null) value
    Capture1.PNG

    This should allow you to continue using the system without any problems.
     
  15. genowhirl9999

    genowhirl9999

    Joined:
    Jun 24, 2016
    Posts:
    11
    Ah thanks, that makes sense. I'll give it a shot. Basically I want a gameobject but I want to guarantee it has a certain component and this method usually works well for me. Unity will also only show objects with that component in the dropdown which is pretty nice.
     
  16. lolimilk

    lolimilk

    Joined:
    Dec 17, 2018
    Posts:
    15
    i want to use this method on editor
    Code (CSharp):
    1.  public static bool ChangeKey<TKey, TValue>(this IDictionary<TKey, TValue> dict,
    2.                                            TKey oldKey, TKey newKey)
    3.     {
    4.         TValue value;
    5.         if (!dict.TryGetValue(oldKey, out value))
    6.             return false;
    7.  
    8.         dict.Remove(oldKey);  // do not change order
    9.         dict[newKey] = value;  // or dict.Add(newKey, value) depending on ur comfort
    10.         return true;
    11.     }
    unity Dictionary can work
    but serializable Dictionary don't work
     
  17. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    798
    When you say on editor you mean while not in play mode? What do you mean with "unity Dictionary can work"?
     
  18. Last_Imba

    Last_Imba

    Joined:
    Feb 25, 2017
    Posts:
    43
    Hi! I have the next problem:

    I have an Dictionary:
    Code (CSharp):
    1.   [System.Serializable]
    2.     public class IngridientDataToInt : SerializableDictionaryBase<IngridientData, int> {
    3.  
    4.     }
    And i can't add more then one item to a dictionary.
    upload_2019-10-2_23-27-51.png

    When I press "+" nothing happens.
    I try to create <string,int> dictionary and it works fine. Can I use ScriptableObjects as keys in dictionary?

    I have read this branch, but did not find the same situation.
     
    Last edited: Oct 3, 2019
  19. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    798
    Hello,

    Could you send me your code via PM so I can test it out?
     
  20. Last_Imba

    Last_Imba

    Joined:
    Feb 25, 2017
    Posts:
    43
    Done.
     
  21. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    798
    Got it and responded with a solution
     
  22. MaeL0000

    MaeL0000

    Joined:
    Aug 8, 2015
    Posts:
    35
    Hi @Rotary-Heart ,

    I imported your package and set up a dictionary like so:
    Code (CSharp):
    1. [Serializable]
    2.     public class BonesDictionary : SerializableDictionaryBase<string, string> {}
    I'm not getting any errors or warnings in the console but the dictionary is just not showing up in the inspector.
    I'm using Unity 2019.3.0b3.

    Any idea what's going on?
     
  23. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    798
    Hello,

    How did you declared your dictionary field?
     
  24. FrogFlakes

    FrogFlakes

    Joined:
    Jun 19, 2017
    Posts:
    4
    Hello,

    I'm attempting to create a finite state machine using a dictionary and thought your tool might be useful to store the states and their related states they can transition to. I'm using Daniel Everland's Scriptable Object Architecture to create the StringVariable scriptable objects. I have one StringVariable object to store the game object's current state. I have a dictionary of StringVariable Objects to a) store key of a possible state of StringVariable object (i.e. Idle) and b) store a value of a list of StringVariable objects (i.e. Walking, Jumping) as the states the original state can transition to.

    I'm able to create a Dictionary with a single key, but adding more I get this error:

    Code (csharp):
    1.  
    2. Couldn't find ScriptableObjectArchitecture.StringVariable reference.
    3. UnityEngine.Debug:LogError(Object)
    4. Standard_Assets.Rotary_Heart.SerializableDictionary.SerializableDictionaryBase`2:UnityEngine.ISerializationCallbackReceiver.OnAfterDeserialize() (at Assets/Standard Assets/Rotary Heart/SerializableDictionary/SerializableDictionaryBase.cs:340)
    5. UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr) (at C:/buildslave/unity/build/Modules/IMGUI/GUIUtility.cs:179
    Following the docs, I edited the RequiredReferences to include objects of StringVariable type. And used the newly modified RequiredReferences asset in my attached script. My code:

    Code (csharp):
    1. using UnityEngine;
    2. using ScriptableObjectArchitecture;
    3.  
    4. namespace Standard_Assets.Rotary_Heart.SerializableDictionary.References
    5. {
    6.     public class RequiredReferences : ScriptableObject
    7.     {
    8.         // ...
    9.         // Custom
    10.         [SerializeField] private StringVariable _stringVariable;
    11.     }
    12. }
    Reading over the comments again on RequiredReferences I noticed "This should only be used for UnityEngine.Object inherited classes".

    Here is the current script attached to the game object:

    Code (csharp):
    1. using System;
    2. using System.Collections.Generic;
    3. using ScriptableObjectArchitecture;
    4. using Rotary_Heart.SerializableDictionary;
    5. using UnityEngine;
    6.  
    7. namespace Enemy
    8. {
    9.     public class EnemyStates : MonoBehaviour
    10.     {
    11.         [Serializable]
    12.         public class StateList : SerializableDictionaryBase<StringVariable, ToStatesListClass>
    13.         {
    14.             public SerializableDictionaryBase<StringVariable, ToStatesListClass> stateList;
    15.         }
    16.  
    17.         [Serializable]
    18.         public class ToStatesListClass
    19.         {
    20.             public List<StringVariable> toStates;
    21.         }
    22.  
    23.         [SerializeField] private StateList stateToStatesList;
    24.     }
    25. }
    Is it possible to use custom object types in the dictionary outside of UnityEngine.Object?
     
  25. FrogFlakes

    FrogFlakes

    Joined:
    Jun 19, 2017
    Posts:
    4
    Oops, just saw this post. Inserting a dummy StringVariable object into the field in RequiredReferences.asset seemed to fix it. Can add keys now. Thank you so much for making this asset!
     
    Rotary-Heart likes this.
  26. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    798
    I'm glad to see that you were able to resolve your issue. Enjoy!
     
  27. SirStompsalot

    SirStompsalot

    Joined:
    Sep 28, 2013
    Posts:
    112
    Hey @Rotary-Heart ,

    I just started using your asset today and its been a blast so far. One thing I'm having a devil of a time getting nested serialized dictionaries to save. I referenced a post you made some time ago, and hoped you might provide some insight.

    In the code below, I have my
    Save
    object saving and loading
    RealmStateDictionary
    successfully. However, each RealmStateDictionary needs to save a dictionary of BuildingData and so far I've not had much luck.

    Any advice?

    Code (CSharp):
    1.  
    2. namespace Project
    3. {
    4.  
    5.     [System.Serializable]
    6.     public class BuildingData
    7.     {
    8.         public int Level { get; set; }
    9.         public BuildingType Type { get; set; }
    10.         public ResourceType ResourceType { get; set; }
    11.     }
    12.  
    13.     [Serializable]
    14.     public class RealmState
    15.     {
    16.         public List<int> BuildingCount = new List<int>();
    17.  
    18.         public Dictionary<Vector2Int, BuildingData> buildingData = new Dictionary<Vector2Int, BuildingData>();
    19.     }
    20.    
    21.     [Serializable]
    22.     public class RealmStateDictionary : SerializableDictionaryBase<Vector2Int, RealmState> { }
    23.  
    24.     [Serializable]
    25.     public class BuildingDataDictionary : SerializableDictionaryBase<Vector2Int, BuildingData> { }
    26.  
    27.     [Serializable]
    28.     public class SaveData
    29.     {
    30.         [Serializable]
    31.         public struct PlayerRealms
    32.         {
    33.             public int Seed;
    34.             public int StructureCount;
    35.             public Vector3 CameraPosition;
    36.             public BiomeType BiomeType;
    37.             public Vector2Int WorldPosition;
    38.             public List<Data.ResourcePair> Resources;
    39.             public List<Vector2Int> destroyedEntities;
    40.         }
    41.  
    42.         public Vector3 RealmsCameraPosition;
    43.         public Player PlayerData = new Player();
    44.         public List<WorldEntities> Entities = new List<WorldEntities>();
    45.  
    46.         [SerializeField]
    47.         public Dictionary<Vector2Int, RealmState> Realms = new Dictionary<Vector2Int, RealmState>();
    48.     }
    49.  
    50.  
    51.     public class Save
    52.     {
    53.         private static SaveData _save;
    54.         private static SaveData save
    55.         {
    56.             get
    57.             {
    58.                 if(_save == null)
    59.                 {
    60.                     _save = Load();
    61.                 }
    62.                 return _save;
    63.             }
    64.         }
    65.  
    66.         [SerializeField]
    67.         public static RealmStateDictionary dataHolder;
    68.  
    69.         private static SaveData Load()
    70.         {
    71.             BinaryFormatter bf = new BinaryFormatter();
    72.             applySurrogates(ref bf);
    73.             SaveData data = new SaveData();
    74.             string filePath = Application.persistentDataPath + "/game.save";
    75.  
    76.             if (!File.Exists(filePath))
    77.             {
    78.                 Debug.Log("Save doesn't exist, creating");
    79.                 using (FileStream file = File.Create(filePath))
    80.                 {
    81.                     var tmpSave = new SaveData();
    82.                     dataHolder = new RealmStateDictionary();
    83.                     dataHolder.CopyTo(data.Realms);
    84.                     bf.Serialize(file, data);
    85.                     return data;
    86.                 }
    87.             }
    88.             else
    89.             {
    90.                 using (FileStream file = new FileStream(filePath, FileMode.Open))
    91.                 {
    92.                     data = (SaveData) bf.Deserialize(file);
    93.                     return data;
    94.                 }
    95.             }
    96.         }
    97.     }
    98. }
    99.  
     
  28. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    798
    Hello,

    Are you getting any errors when trying to save it? Also, by save it, do you mean using the BinaryFormatter to save the data to a file? I don't see any saving logic here, so it's hard to tell what could be happening. Also, your RealmStateDictionary field is static so why do you need the serializable dictionary?
     
  29. SirStompsalot

    SirStompsalot

    Joined:
    Sep 28, 2013
    Posts:
    112
    Hi Rotary,

    I do get an error, which you covered before.
    SerializationException: Type 'RotaryHeart.Lib.SerializableDictionary.DrawableDictionary' in Assembly 'Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable.
     
  30. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    798
    That error would only appear if you are serializing/deserializing a serializable dictionary, on the code above I don't see you doing that anywhere. Did you miss any function when you pasted it here?
     
  31. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    798
    Version 2.6.8 has been submitted to the asset store for review. This version includes:
    • Patch fix to allow custom property drawers to show the dictionary without problems.
     
  32. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    798
    Great news, version 2.6.8 is now live!
     
  33. TheDanimal

    TheDanimal

    Joined:
    Dec 7, 2016
    Posts:
    4
    Huge fan! This has been making my life a lot easier.

    I'm running into an issue with a dictionary of classes which derive from an abstract class and for the life of me I can't pinpoint why it won't draw in the inspector. Works wonders on everything else except for this abstract base class.


    NullReferenceException: Object reference not set to an instance of an object
    RotaryHeart.Lib.SerializableDictionary.DictionaryPropertyDrawer.OnGUI (UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label) (at Assets/Rotary Heart/SerializableDictionary/Editor/DictionaryPropertyDrawer.cs:315)
     
  34. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    798
    Send me your code so I can see what the issue is.
     
  35. ZeKassaK

    ZeKassaK

    Joined:
    Sep 29, 2014
    Posts:
    11
    Hello, I'm using your asset and I have a question, this is what I have :

    Code (CSharp):
    1. [Serializable]
    2. public class ChestItems : SerializableDictionaryBase<ItemData, Item> { }
    3.  
    4. [Serializable]
    5. public class Player
    6. {
    7.    public ChestItems ChestItems = new ChestItems();
    8. }
    ItemData and Item are [Serializable] too.

    I need to serialize to Json the Player class with :

    Code (CSharp):
    1. string jsonData = JsonUtility.ToJson(Player.Instance, true);
    This is working well, in jsonData I have all my datas and the dictionary ChestItems but I have a lots of unecessary datas, if I check the jsonData string I have :

    Code (JavaScript):
    1. "ChestItems":{
    2.       "reorderableList":{  },
    3.       "reqReferences":{  },
    4.       "isExpanded":false,
    5.       "_keyValues":[  ],
    6.       "_keys":[  ],
    7.       "_values":[  ]
    8.    },
    In this case I only need the _keyValues array like :

    Code (JavaScript):
    1. "ChestItems":{
    2.       "_keyValues":[  ],
    3.    },
    or without _keyValues like directly :

    Code (JavaScript):
    1. "ChestItems":{
    2.       [  ]
    3.    },
    How can I do that ? Thanks !
     
  36. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    798
    Unfortunately that can't be done with current version and JsonUtility, if you use any other Json system that allows you to mark fields to ignore you will be able to do it.

    The pro version, which is under development and to be published soon, has been completely re written to allow this to be used without extra data on the json string.
     
  37. TheDanimal

    TheDanimal

    Joined:
    Dec 7, 2016
    Posts:
    4
    Code (CSharp):
    1. [Serializable]
    2. public abstract class Vital
    3. {
    4.     protected Entity entity;
    5.     protected AttributeDict attributes;
    6.     protected SkillDict skills;
    7.  
    8.  
    9.     public Vital()
    10.     {
    11.         entity = Player.localPlayer;
    12.         attributes = entity.attributes;
    13.         skills = entity.skills;
    14.     }
    15.  
    16.     public abstract float max { get; }
    17.     public abstract float level { get; set; }
    18.     public abstract float threshold { get; }
    19.     public abstract float recoveryRate { get; }
    20.     [TextArea(10,20)] public string tooltip;
    21. }
    22. abstract and a derived class, nothing special
    23. [Serializable]
    24. public class Stamina : Vital
    25. {
    26.     public override float max { get;  }
    27.     public override float level { get; set; }
    28.     public override float threshold { get { return max * -1; } }
    29.     public override float recoveryRate { get; }
    30. }
    Code (CSharp):
    1. [Serializable]
    2. public class VitalsDict : SerializableDictionaryBase<string, Vital>
    3. {
    4.     public VitalsDict()
    5.     {
    6.         int i = 0;
    7.         foreach (string name in Enum.GetNames(typeof(VitalName)))
    8.         {
    9.             //Add(name.Replace("_", " "), new Vital());
    10.             i++;
    11.         }
    12.     }
    13. }
    Dictionary class here

    Code (CSharp):
    1. public class Player : Entity
    2. {
    3.     public static Player localPlayer = new Player();
    4.  
    5.     public void Awake()
    6.     {
    7.         localPlayer = this;
    8.  
    9.         foreach (Attributes att in attributes.Values)
    10.             att.level = 50;
    11.  
    12.         vitals.Add("Stamina", stamina);
    13.     }
    14. }
    Player class where Stamina is added to VitalsDict


    NullReferenceException: Object reference not set to an instance of an object
    RotaryHeart.Lib.SerializableDictionary.DictionaryPropertyDrawer.OnGUI (UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label) (at Assets/Rotary Heart/SerializableDictionary/Editor/DictionaryPropertyDrawer.cs:315)
    UnityEditor.PropertyDrawer.OnGUISafe (UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label) (at /Users/builduser/buildslave/unity/build/Editor/Mono/ScriptAttributeGUI/PropertyDrawer.cs:23)
    UnityEditor.PropertyHandler.OnGUI (UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, System.Boolean includeChildren, UnityEngine.Rect visibleArea) (at /Users/builduser/buildslave/unity/build/Editor/Mono/ScriptAttributeGUI/PropertyHandler.cs:139)
    UnityEditor.GenericInspector.OnOptimizedInspectorGUI (UnityEngine.Rect contentRect) (at /Users/builduser/buildslave/unity/build/Editor/Mono/Inspector/GenericInspector.cs:100)
    UnityEditor.UIElements.InspectorElement+<CreateIMGUIInspectorFromEditor>c__AnonStorey1.<>m__0 () (at /Users/builduser/buildslave/unity/build/Editor/Mono/Inspector/InspectorElement.cs:495)
    UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr) (at /Users/builduser/buildslave/unity/build/Modules/IMGUI/GUIUtility.cs:179)


    Dictionary won't draw in inspector at runtime. Tried to track it down but it was a bit above my pay grade. If I remove abstract from the base class it displays normally.

    Thanks for all your hard work, this dictionary really has made my life much easier :)

    cheers
     
  38. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    798
    That's because unity doesn't serialize abstract classes, if you try to serialize any abstract class it won't be shown on your inspector. So the issue you are seeing is the dictionary trying to find a serializable type (Vita) that Unity won't serialize, so it doesn't find anything. That's an Unity serialization limitation. Try adding
    public Vital stam;
    to any script and you'll see that it doesn't show on the inspector.
     
    TheDanimal likes this.
  39. TheDanimal

    TheDanimal

    Joined:
    Dec 7, 2016
    Posts:
    4
    I'll have to sort out a way to avoid having the base class abstract. Good to know, thanks for getting back!
     
  40. Garuruman

    Garuruman

    Joined:
    Feb 24, 2018
    Posts:
    3
    Hello, quick question, because I couldn't find any similar problem in previous posts.

    I have a dictionary which uses an enum as a key, and it works great. Now, if I have that serialized dictionary with an enum selected in the editor and delete that enum in the code, the editor bugs out and it doesn't let me click on any item of this dictionary. Also, the "-" icon disappears. All other serialized dictionaries work fine.

    I can get around the problem by creating a dummy enum, which then auto replaces the missing enum in the editor, and then I can delete it. But it's a bit of a hassle :)
    Anything I'm doing wrong? Is it a known bug?
    Bugged.png Others working.png
     
  41. TheDanimal

    TheDanimal

    Joined:
    Dec 7, 2016
    Posts:
    4
    Quick followup on this issue. While the abstract class may still have played a role, I think the error was due to varying amounts and types of fields between different derived classes I had stored in my dictionary. It appears it won't play nice if the dictionary contains KVP's if the different classes(values) contain different fields to be serialized.

    The solution was to declare all the members I need for the derived classes in the parent class. Some of the derived classes wind up with an unused property or two, but the functionality works and the dictionary serializes happily.
     
  42. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    798
    Is it throwing any error? This is the first time someone reports this bug.
     
  43. Garuruman

    Garuruman

    Joined:
    Feb 24, 2018
    Posts:
    3
    Nope, didn't get any errors, but I haven't tested it more. I guess it's easily reproducible if you want to check for yourself.
    It doesn't bother anyway, I mentioned it just in case there was something I was doing incorrectly. Thanks for the answer anyway :)
     
  44. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    798
    Great news everyone!

    New version Pro is almost complete and ready to be published, it has been completely rewritten to allow many new features. A full feature list will be available once it's ready to be published, but one of the key features is the new serialization/deserialization method used that gives better data handling, thus making it better. Here's a quick comparison for a serialized Json using the same dictionary in both versions.

    Code (CSharp):
    1. {
    2.     "reorderableList": {
    3.         "canAdd": true,
    4.         "canRemove": true,
    5.         "draggable": true,
    6.         "expandable": true,
    7.         "multipleSelection": true,
    8.         "isExpanded": true,
    9.         "label": {
    10.             "m_Text": "Keys",
    11.             "m_Image": {
    12.                 "instanceID": 0
    13.             },
    14.             "m_Tooltip": ""
    15.         },
    16.         "headerHeight": 18.0,
    17.         "footerHeight": 13.0,
    18.         "slideEasing": 0.15000000596046449,
    19.         "verticalSpacing": 2.0,
    20.         "showDefaultBackground": true,
    21.         "elementDisplayType": 0,
    22.         "elementNameProperty": "",
    23.         "elementNameOverride": "",
    24.         "elementIcon": {
    25.             "instanceID": 0
    26.         }
    27.     },
    28.     "reqReferences": {
    29.         "instanceID": 0
    30.     },
    31.     "isExpanded": true,
    32.     "_keyValues": [
    33.         "Key1",
    34.         "Key2",
    35.         "Key3",
    36.         "Key4"
    37.     ],
    38.     "_keys": [
    39.         "Key1",
    40.         "Key2",
    41.         "Key3",
    42.         "Key4"
    43.     ],
    44.     "_values": [
    45.         1,
    46.         2,
    47.         3,
    48.         4
    49.     ]
    50. }
    51.  
    Code (CSharp):
    1. {
    2.     "m_val": 7,
    3.     "reqReferences": {
    4.         "instanceID": 0
    5.     },
    6.     "m_keys": [
    7.         "Key1",
    8.         "Key2",
    9.         "Key3",
    10.         "Key4"
    11.     ],
    12.     "m_values": [
    13.         1,
    14.         2,
    15.         3,
    16.         4
    17.     ]
    18. }
     
  45. ANUBISKONG

    ANUBISKONG

    Joined:
    Nov 16, 2016
    Posts:
    47
    I got a error when I call Remove function without GameObject selecting in Hierarchy.
    It seems like if Serializable Dictionary dont show dict table in Inspector at least once, _keys and _values won't hold a intact list of dict keys and values.


    Error message:

    ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
    Parameter name: index
    System.ThrowHelper.ThrowArgumentOutOfRangeException (System.ExceptionArgument argument, System.ExceptionResource resource) (at <437ba245d8404784b9fbab9b439ac908>:0)
    System.ThrowHelper.ThrowArgumentOutOfRangeException () (at <437ba245d8404784b9fbab9b439ac908>:0)
    System.Collections.Generic.List`1[T].RemoveAt (System.Int32 index) (at <437ba245d8404784b9fbab9b439ac908>:0)
    RotaryHeart.Lib.SerializableDictionary.SerializableDictionaryBase`2[TKey,TValue].Remove (TKey key) (at Assets/Rotary Heart/SerializableDictionary/SerializableDictionaryBase.cs:225)
     
  46. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    798
    How did you add your elements? When and where are you calling the remove? Could you send a repro project/package?
     
  47. ANUBISKONG

    ANUBISKONG

    Joined:
    Nov 16, 2016
    Posts:
    47
    I added some elements in Inspector before game running, other elements added by code at runtime, remove is called by code at runtime too.
     
  48. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    798
    Can you send a repro project/package? I haven't seen this issue before and I cannot reproduce it.
     
  49. ANUBISKONG

    ANUBISKONG

    Joined:
    Nov 16, 2016
    Posts:
    47
    I had send a conversation to you
     
    Rotary-Heart likes this.
  50. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    798
    I've sent you a possible fix