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
3
Question by Veehmot · Feb 15, 2012 at 05:35 AM · editoreditor-scriptingserializationeditorwindow

OnSerialize event

Is possible to be told after serialization occurs for objects, in the Editor?


I know that Unity3D serializes some variables (as described in the **SerializeField** manual page).

After importing a script something in my project, clicking play, or going back from play mode, Unity3D recreates all the objects in memory, and reset all serializable fields. That's why when I Debug.Log() a public variable (like int), it says the default value, but when I access it with other script it says the previous stored (serialized) value.

What I want to know is when serialization takes place, to sew my variables in the editor to a more proper object. The **manual** refers to this process of sewing:

Hint: Unity won't serialize Dictionary, however you could store a List for keys and a List for values, and sew them up in a non serialized dictionary on Awake(). This doesn't solve the problem of when you want to modify the dictionary and have it "saved" back, but it is a handy trick in a lot of other cases.

Thing is, in the Editor I can't use the Awake function. I've tried OnEnable, OnBecameVisible, Start, Awake and Reset with no help: none of these functions are called after I make a change in the scripts. The constructor is called, but as I mentioned earlier, it contains the constructor values.

Any help would be much appreciated.

Comment
Add comment · Show 1
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 hvilela · Mar 16, 2012 at 11:07 PM 0
Share

Same problem here.

2 Replies

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

Answer by Veehmot · Jun 02, 2013 at 09:16 PM

This blog post answered my question:

http://blogs.unity3d.com/2012/10/25/unity-serialization/

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

Answer by rutter · Mar 17, 2012 at 12:03 AM

You might be able to use a twist on lazy initialization:

 //by default, we have a 'null' dictionary
 //the first time we access it, create and sew
 private Dictionary<Foo> _d;
 public Dictionary<foo> d
 {
     get
     {
         if (_d == null)
         {
             _d = new Dictionary<foo>();
             Sew();
         }
         return _d;
     }
     set
     {
         _d = value;
     }
 }
 
 public void Sew()
 {
     //do stuff
 }

This seems like it should re-create and re-sew the dictionary each time you get a new object.

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

7 People are following this question.

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

Related Questions

Changes to Object made in custom Editor Window don't persist 0 Answers

How do you save changes made with custom editor? 3 Answers

Is there a way to avoid the Animation window drop-down menu with a selected Animator? 0 Answers

Is it possible to detect drag and drop in hierachy window? 0 Answers

SerializedProperty with children class fields 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