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
1
Question by crazymonkay · Jun 24, 2014 at 07:13 PM · serializationscriptableobjectdictionary

Serializing Dictionary: Data lost between sessions

Hello all,

So I have myself a ScriptableObject that save in my assets and want to use as a prefab. In this object I have a Dictionary. As you may know Unity does not serialize Dictionaries, but lucky for us in 4.5 they gave us these handy little methods, and even luckier for me the example they gave is supposed to do exactly what I need.

I copy those example methods and viola! They work like a charm... Until I close and reopen Unity... Data persists in my current session, but when I close and reopen Unity all of my data is lost. After spending hours searching for a working fix I'm pretty much at the end of my rope here. How can I fix this?

UPDATE: Upon further mucking about with this, I think I have narrowed the problem down to my editor script. Basically, among other things, I replaced the Dictionary<> with a List<>, which Unity DOES serialize. However, with my editor script enabled the problem persists. When I disable my editor script and use the default inspector, I can still see all of my data in the inspector and the problem does not occur.

My fixed code that uses a List <-- Using this script without a custom editor has no issues, but it's a not-so-ideal implementation IMO

My original code that uses a Dictionary

My editor script used for the original code

Comment
Add comment · Show 2
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 rutter · Jun 24, 2014 at 07:21 PM 0
Share

Easier to help if you post your code (or at least an example we can use).

At a glance, I'd check to make sure those key/value lists are being serialized in the first place. Are they visible in the inspector?

avatar image crazymonkay · Jun 24, 2014 at 07:41 PM 1
Share

Added my code to the original post. "Are they visible in the inspector" is kind of hard to answer, cause I had to write a custom editor script for it. But as I said earlier, all data appears to be serialized properly in the current session of Unity. All data persists between edit and play mode, after scripts are complied, etc.

0 Replies

· Add your reply
  • Sort: 

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

22 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

Related Questions

[Solved]How to serialize Dictionary with Unity Serialization System 6 Answers

please help me, Scriptable object's variable serialization issue 1 Answer

Creating ScriptableObject Asset "Failed to write meta file" 1 Answer

Serialization issue with ScriptableObject 0 Answers

Nested Dictionary data lost after playmode 0 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