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 Danvil · Sep 05, 2014 at 02:52 PM · editor-scriptingserialization

OnBeforeSerialize constantly called in Editor Mode

One of my scripts which also runs in the editor (ExecuteInEditMode) requires some custom code for serialization. So I derived my class from ISerializationCallbackReceiver and implemented OnBeforeSerialize and for OnAfterDeserialize.

I noticed that the OnBeforeSerialize is constantly called serveral times per second. This happens although there are no changes on the object.

Why is this happening? I would assume that the serialization is only called when necessary (i.e. starting the game, or saving the scene).

As my serialization code is quite heavy on the CPU it should be called only if necessary.

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 Landern · Sep 05, 2014 at 03:25 PM 0
Share

I would read the blog post about the introduction to ISerializationCallbackReceiver, there are a LOT of gotcha's depending on how you construct objects, what they derive from and whether unity is going to just (de)serialize ad nauseam to ensure the internal stream has the newest information. If you go through the comments on the blog post they explain quite a bit, this includes sixtrillionbillion calls and why it may be happening.

avatar image dCalle · Jul 23, 2017 at 08:58 AM 0
Share

Am also wondering...

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Bunny83 · Jul 23, 2017 at 09:29 AM

Unity uses the serialization system for accessing the properties of an object and showing them in the inspector. That's represented by the SerializedObject and SerializedProperty in editor code. They don't have a direct reference to the actual object / value but represent the serialized data. So whenever the Inspector window is redrawn / updated or receives an event the serialized data need to be updated in order to show the actual values in the inspector.

It's more or less mentioned in the blog post that Landern linked in the comment above as the second bulletpoint:

Serialization of “things” is at the very core of Unity. Many of our features build ontop of the serialization system:

Inspector window. The inspector window doesn’t talk to the C# api to figure out what the values of the properties of whatever it is inspecting is. It asks the object to serialize itself, and then displays the serialized data.

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

25 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

Related Questions

Custom editor, serialize and prefab issue 0 Answers

Preview procedural texture in scene without serializing it? 1 Answer

Filling list with editor scripts is empty on Play 1 Answer

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

Keeping object between edit and play modes. 1 Answer


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