Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at id.unity.com during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.


    Read our full announcement for more information and let us know if you have any questions.

[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:
    817
    Version 2.6.9 has been submitted to the asset store for review. This version includes:
    • Fixed issue that if the dictionary wasn't drawn it would throw an error when adding an element via code.
     
  2. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    817
    Great news, version 2.6.9 is now live! Fixing the issue reported here

     
  3. Jqob

    Jqob

    Joined:
    Dec 20, 2018
    Posts:
    35
    Hi. I have a problem with enums as key. All works fine except that when I try to choose them from drop-down menu in the inspector, I cannot. I have to add multiple enums until I get the one I wanted to assign to the dictionary and remove the other ones.
     
  4. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    817
    I'm not seeing that issue here. Could you show an image of what issue you are getting?
     
  5. Jqob

    Jqob

    Joined:
    Dec 20, 2018
    Posts:
    35


    You see, I cannot select the enums I want from the drop down.
     
  6. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    817
    Ok I was able to replicate this with the asset store version. Pushing a hot fix now, if you want to have this fix faster send me a message so I can send you the package.
     
    Jqob likes this.
  7. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    817
    Version 2.6.9.1 has been submitted to the asset store for review. This version includes:
    • Hot fix for not able to change enum key
     
    Jqob likes this.
  8. Jqob

    Jqob

    Joined:
    Dec 20, 2018
    Posts:
    35
    Thanks bro! I'll wait for the asset release, dont worry
     
    Rotary-Heart likes this.
  9. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    817
    Great news, version 2.6.9.1 is now live!
     
  10. OmegaRogue

    OmegaRogue

    Joined:
    Apr 25, 2017
    Posts:
    7
    Im getting a
    NullReferenceException: Object reference not set to an instance of an object
    when i start a build with code using these Serialized Dictionaries, im using Unity 2019.3.3f1, the Dictionary is in a ScriptableObject
     
  11. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    817
    I'll need more information to be able to help you out. What's the full stack trace? What dictionary type are you using? Are you running any preprocess script on that ScriptableObject?
     
  12. CarlHaeggman

    CarlHaeggman

    Joined:
    Oct 15, 2018
    Posts:
    7
    Hello! Just wondering if I can use this in a Custom UI to display a dictionary? Might sound like a dumb question, I am relatively new to programming.
     
  13. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    817
    Hello, what do you mean with custom UI? What are you trying to do? This inspector will only work on the editor.
     
  14. CarlHaeggman

    CarlHaeggman

    Joined:
    Oct 15, 2018
    Posts:
    7
    Code (CSharp):
    1.  private void OnGUI(){
    2.  
    3. EditorGUILayout.Propertyfield("PUT DICTIONARY HERE?")
    4.  
    5. }
    Basically what I want to do is that I want to use a OnGUI function to show and edit the dictionary using a property field or some other function. Kind of lost right now.

    The above code is not my actual code and is just a "showcase" of what I want to do.
     
  15. mrCharli3

    mrCharli3

    Joined:
    Mar 22, 2017
    Posts:
    982
    Is it possible to save/load these with JsonUtility as well?
     
  16. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    817
    Yes, you should be able to do that.

    Yes you can, but as for this version it will populate your json with extra data.
     
  17. Fangh

    Fangh

    Joined:
    Apr 19, 2013
    Posts:
    281
    Hello I have this error :

    "A key of type: Item requires to have a valid RequiredReferences reference"

    This how my "Item" class (it's a ScriptableObject) looks like :

    2020-03-23 00_57_26-Item.cs - Test - Visual Studio Code.png

    This is a CountableItemDictionary:

    2020-03-23 00_57_42-InventoryManager.cs - Test - Visual Studio Code.png

    This is my RequiredReferences class looks like :
    2020-03-23 00_58_09-RequiredReferences.cs - Test - Visual Studio Code.png

    This is how my RequiredReferences asset looks like :
    upload_2020-3-23_0-59-57.png

    This is how I intend to use my CountableItemDictionary :
    upload_2020-3-23_1-0-27.png

    can someone helps me ?
     
  18. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    817
    Did you add the
    ReqReferences
    to your object instance? I pasted your code and it's working without issues.
    upload_2020-3-22_20-20-17.png
     
    Fangh likes this.
  19. Fangh

    Fangh

    Joined:
    Apr 19, 2013
    Posts:
    281
    Oh ! I did not know I had to... Sorry. You are so nice to test it so quickly ! Thank you !!!
     
    Rotary-Heart likes this.
  20. Stexe

    Stexe

    Joined:
    Feb 2, 2014
    Posts:
    218
    Is there a paid version coming out? I noticed you changed the free to "Lite" ... so I assume the paid one is coming soon? Last time I saw you mention it was in December 2019. Just curious. Haven't used this asset yet but I'm about to dive in.

    Also, how well does this work with 2019.3? I know they have Serialized Generic Lists now that I've been using.

    EDIT: Also, you should update your SupportWindow.cs ... you're missing a line break in the UI for the Tools menu which is standard convention and you're using the old Unity Asset Store URL (they got rid of the "3D" part).
     
    Last edited: Apr 6, 2020
    Rotary-Heart likes this.
  21. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    817
    Hello, yes the paid version is coming out soon, is currently under closed beta testing. Hopefully it will be published soon. I'll be posting here when the version is out.

    Yes everything works fine on all unity versions. I'm currently using it with 2019.3 and 2020 without issues at all.
     
    Stexe likes this.
  22. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    817
    Stexe likes this.
  23. as3mbus

    as3mbus

    Joined:
    Dec 5, 2016
    Posts:
    71
    Any plan to make the lite version into UPM package ?

    i'm just lately getting into how UPM make my asset directory more clean
     
  24. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    817
    Is something that I've been thinking of, once the pro version is out and stable enough I will check into making the lite version a package.
     
  25. Rubakai

    Rubakai

    Joined:
    Aug 27, 2015
    Posts:
    32
    Hi Rotary-Heart, looking forward to the Pro version. One issue I'm having with my latest dictionary is when trying to save the dictionary using binaryformatter. Its working with a normal dictionary, however with your serialized dictionary I'm getting the usual error "SerializationException: Type 'RotaryHeart.Lib.SerializableDictionary.DrawableDictionary' in Assembly 'Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable."

    Not sure why as everything is serializable. Is it because Ive got a list in the object (this works with the normal dictionary)

    Code (CSharp):
    1. [Serializable]
    2. public class QuadrantObject
    3. {
    4.     public SectorLocation sectorLocation;
    5.     public QuadrantLocation QuadrantLocation;
    6.     public List<Planets> planets;
    7.     public List<Stars> stars;
    8.     private float discovery;
    9. }
    10.  
    11. [Serializable]
    12. public class QuadrantDictionary : SerializableDictionaryBase<string, QuadrantObject>{}
    13.  
    14. [SerializeField]
    15.     private QuadrantDictionary quadrantDictionary;
     
    Last edited: May 10, 2020
  26. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    817
    Hello,

    That's an unfortunate known limitation of the lite version. You can work around it by instead of serializing the serialized dictionary copying it to a Dictionary then serializing that copy Dictionary with the BinaryFormatter, I understand that this is not the best workaround, but it is currently the only way to make it work with the Lite version.

    The pro version has been rewritten completely and this issue does not happen with this version. This is one of the many new and different things between both systems.

    EDIT: Pro version thread can be found here https://forum.unity.com/threads/serializable-dictionary-pro.869377/
     
    Last edited: May 10, 2020
    Stexe likes this.
  27. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    817
    Version 2.6.9.3 has been submitted to the asset store for review. This version includes:
    • Small fix for inspector indentation
    • Modified definer to use a general approach
     
  28. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    817
    Great news, version 2.6.9.3 is now live!
     
  29. shortlin

    shortlin

    Joined:
    Oct 30, 2014
    Posts:
    22
    Did anyone use it apear the Error?:
    ====
    GUI Error: You are pushing more GUIClips than you are popping. Make sure they are balanced.
    UnityEngine.GUIUtility: ProcessEvent(Int32, IntPtr)
    ====

    But it apeared just one moment,Unity still could run,Is it OK?
     
  30. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    817
    Never got a report for that, were you able to replicate the issue? Do you have a repro steps/project for that? That is an editor drawing error so it shouldn't block your game in any way.
     
  31. shortlin

    shortlin

    Joined:
    Oct 30, 2014
    Posts:
    22
    It didn't always happen.It sometimes happened when I added new folder or file in Unity.

    Before I use this plug-in.
    I had used the guy's method.It would happen the same error.
    I am afraid it would be some bad effect in future.Although the error message appeared a little time and then disappeared.

    By the way my Unity is 2019.4.1f1
     
  32. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    817
    That might be an Unity bug then, that doesn't have anything to do with the drawing of this system since it doesn't happen when you manipulate your dictionary data. Where does the error points to?
     
  33. shortlin

    shortlin

    Joined:
    Oct 30, 2014
    Posts:
    22
    That's t the problem weird place.... there are no points to tell me where make this error...
     
  34. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    817
    Then it's most likely an unity bug. Since this is the first time I see this report. Either way, as I said earlier that's just an Editor drawing error. It will not affect your game in any way.
     
  35. tonygiang

    tonygiang

    Joined:
    Jun 13, 2017
    Posts:
    71
    Hi. Will you add support for serializing array/List as value type for Serializable Dictionary?
     
  36. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    817
    Hello. That is already implemented, check the Advanced Dictionary section on the documentation. It has an example too
     
    Stexe likes this.
  37. tonygiang

    tonygiang

    Joined:
    Jun 13, 2017
    Posts:
    71
    I am asking specifically about the ability to use List/array directly as Value types without additional boilerplate code.
     
  38. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    817
    That's an unfortunate limitation of Unity serialization, not of the system. It doesn't serialize nested array/List without a wrapper.
     
    Stexe likes this.
  39. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    817
    Version 2.6.9.4 has been submitted to the asset store for review. This version includes:
    • Fixed null error edge case when retrieving property height
     
  40. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    817
    Great news, version 2.6.9.4 is now live!
     
    Stexe likes this.
  41. tonygiang

    tonygiang

    Joined:
    Jun 13, 2017
    Posts:
    71
    Hi. Do you have any plan to release Serializable Dictionary Lite as an UPM package?
     
  42. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    817
    Hello, maybe at some point, for now it's staying as an asset store package.
     
  43. Dreoh

    Dreoh

    Joined:
    Aug 15, 2012
    Posts:
    15
    I've tried importing this, but nothing changes when I do.

    I've looked all over your links and in the documentation for why this might be the case. I'm on 2020.3.13f1 if it matters.

    SerializableDictionaryBase type can't be found
     
  44. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    817
    Does the provided example ScriptableObjects work? Did you added the using to your script?

    I'll need to see your code to be able to give any help.
     
  45. Raseru

    Raseru

    Joined:
    Oct 4, 2013
    Posts:
    87
    The DrawableDictionary adds a bunch of stuff to SerializableDictionaryBase that bloats the save file when serializing. Is there a good way to not save that part when serializing to a file without messing with the functionality in Unity?
     
  46. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    817
    Hello, unfortunately with the Lite version not directly. Depending on what you are using for saving your file you can use the CopyFrom/CopyTo to copy the data to a normal Dictionary.

    This issue has been address on the Pro version.
     
  47. tonygiang

    tonygiang

    Joined:
    Jun 13, 2017
    Posts:
    71
    Hi. What rules should I follow if I want to create a library/package that has Serializable Dictionary Lite as a dependancy? Can I host a copy of SDL as a UPM package? Does the Asset Store license allow using AS packages as dependencies?
     
  48. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    817
    Hello, I think that it allows to use other seller assets as dependencies. But you cannot include it, the user of your package will need to download it from the store. This was the response I got last time I asked. Might be better to contact asset store support directly.

    Let me know if you have any more questions.
     
  49. tonygiang

    tonygiang

    Joined:
    Jun 13, 2017
    Posts:
    71
    I got the response from support. Here is the abbreviated exchange:

    Unity: Unless they own the rights to redistribute the free asset, they should not include any of that data in their package, regardless of how they distribute it. Instead, they should give instructions to users on how they can come to the Asset STore to get teh free package.

    Me: Having established that the rights to distribute the free asset are required to distribute said asset, is it understood that I would have these rights if I requested for permission to distribute from the asset author and was granted permission by them?

    Unity: Yes. You should make sure to have it all in writing, as if we get a complaint about redistribution etc, we will generally take action by removing the asset. Realistically, the best option for users is to get the original free asset, as they will get updates with that, as they come

    So, to make it all formal: I would like to create a UPM package based on Serializable Dictionary Lite and submit it on OpenUPM (maybe not immediately, but at some point in the future). Full author attribution. I will try to keep the UPM package up-to-date within my best ability. Any any point, on your request, I will hand over control of a package on OpenUPM to you if the site has that capability, or withdraw my package from OpenUPM if you want to publish your own UPM package of SDL, as you have said that you planned to in this thread. If you want to, you can specify the Reverse-DNS identifier you would like for your planned UPM package of SDL here and I can honor it for the UPM package I'll create for consistency sake. Do I have permission?
     
  50. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    817
    @tonygiang Alright, I'll be creating the package and submit it to OpenUPM in the following days. That way you don't have to keep it updated. Not much should change, so you can keep working on your asset without problems