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 IgorAherne · Oct 30, 2014 at 04:06 AM · serializationscriptableobjectdictionaryinitialization

please help me, Scriptable object's variable serialization issue

I have a dictionary stored in a ScriptableObject, which then is saved as an asset.

 Dictionary<Transform, Nodescript> ScriptViaTransform = new Dictionary<Transform, Nodescript>();

Once I load the asset, my editor classes can pass values for storage, but if I Enter/Exit playmode, it looks like the dictionary re-initializes itself. This wipes all the keys/values :<

Question, how to store the dictionary data in a Scriptable object so that its dictionary doesn't re-initialize itself upon the initialization? And how do I initialize dictionary only once?

Thank you

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Habitablaba · Oct 30, 2014 at 04:29 AM

Since you added the 'serialization' tag, I'm assuming you know your problem is with saving a dictionary to a file, and you're not looking for some in-code magic to persist a variable across runtimes.

Howerver, a dictionary is not serialize-able by default, so you cannot save it to a file and reload its state. There are a bunch of answers and forum posts and tutorials (and assets on the store) which provide the concept of a serialize-able dictionary, so I would start there. Other than that, you can always change data structures, or attempt to write your own version of a serialize-able dictionary.

This, for example, seems like a good place to start.

Comment
Add comment · Show 5 · 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
avatar image IgorAherne · Oct 30, 2014 at 04:51 AM 0
Share

This is bad news :< Is there a way to dump it all in an array and save it in the other scriptable object?

avatar image Habitablaba · Oct 30, 2014 at 04:52 AM 0
Share

Sure, did you look at the link I posted?

avatar image IgorAherne · Oct 30, 2014 at 04:53 AM 0
Share

http://stackoverflow.com/questions/14495476/how-to-add-dictionary-data-in-to-an-array got it, thanks for your time!

avatar image Habitablaba · Oct 30, 2014 at 04:55 AM 0
Share

That's for objective C, but I suppose the concept is sound.

avatar image IgorAherne · Oct 30, 2014 at 05:14 AM 1
Share

Thanks Habitablaba, I've found something that looks very promising and is basically what the other question you've directed me to implements http://docs.unity3d.com/ScriptReference/ISerializationCallbackReceiver.OnBeforeSerialize.html for anybody struggling.

Thank you m8!

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

26 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 avatar image avatar image avatar image

Related Questions

Serializing Dictionary: Data lost between sessions 0 Answers

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

How to store references between scriptableobject assets 3 Answers

ScriptableObject error with Inheritance 2 Answers

In this case the lists do not serialize. Why? 2 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