Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by douglasg14b · Mar 23, 2015 at 10:42 PM · serializationtagdictionary

How to serialize a Dictionary?

I'm trying to modify the TagFrenzy plugin to use a dictionary instead of a list for the tags. The issue I'm running into is that the Dictionary is not being found when I try and use mySerializedDictionary = tagger.FindProperty("MyDictionary"); If I replace "MyDictioanry" with a list of the same name it is found.

Is this possible in unity?

Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image spiceboy9994 · Mar 23, 2015 at 11:15 PM 0
Share

Not sure if you can directly serialize this type of object... but... have you tried to create a wrapper class that Inherits from the dictionary and serialize that one? It helped me out before when serializing complex objects to xml.

avatar image douglasg14b · Mar 24, 2015 at 12:06 AM 0
Share

Pretty much I'm trying to modify TagFrenzy so that when you select a tag from the inspector it modifies a dictionary ins$$anonymous$$d of a list. So that I can do lookups via key, ins$$anonymous$$d of iterating through the list of tags.

avatar image spiceboy9994 · Mar 24, 2015 at 12:16 AM 0
Share

... or use Linq to found your item directly ins$$anonymous$$d of iterating

avatar image douglasg14b · Mar 24, 2015 at 12:32 AM 0
Share

I'm concerned about performance, the last thing I want to use in this situation is LINQ. I'm using multiple tags as a simpler way than type-checking to identify objects that are within a spherical collider of another object. (when you have a few hundred objects all within each others "range" the number of checks for each collider to deter$$anonymous$$e friend from foe, inanimate from animate, shoot this don't shoot that...etc Rises dramatically)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by apple92 · May 31, 2015 at 08:50 AM

Serialization of Dictonaries isn't directly possible in Unity... BUT..

You can use the ISerializationCallbackReceiver. If you additionaly add CallbackReceiver to derive from (Instead of only MonoBehaviour, or something else), you can make changes before and after serialization. Like this you can run through your Dictonary and split it into two List in OnBeforeSerialization(). Lists can nativly be serialized with Unity. OnAfterDeserialize() you would iterate through the Lists and recreate your Dictonary.

Link to the Full explanation:

Here

Like this, your Dictonary should no longer become empty everytime an Assembly gets reloaded, etc.

Regards Michael

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

23 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Serialize a Dictionary 1 Answer

In this case the lists do not serialize. Why? 2 Answers

IL2CPP Dictionary deserialization issue 3 Answers

Serializing Dictionary: Data lost between sessions 0 Answers

Dictionary of Dictionaries - How do I store this and assemble it at runtime? 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges