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 Pangamini · Mar 30, 2015 at 01:46 PM · errorserialization

"Serialization depth limit exceeded" with non-serializable classes

I know there are many threads about this bug or whatever it is, but they all deal with actual serialization. I get these errors for classes that don't derive from unity classes, nor use the unity attributes, also they are loaded from the DLL. So for some reason Unity is checking my classes for its serialization system and feels the urge to tell me 1500 times per code load...

Any ideas how to get rid of it?

Comment
Add comment · Show 30
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 Glurth · Mar 30, 2015 at 05:48 PM 0
Share

If you are using any of those non-serializable classes as public variables in a monobehavior, it IS trying to serializing them. You will need to use a [System.NonSerialized] attribute in front of each such variable to prevent it from serializing. Or make them not-public.

avatar image Pangamini · Mar 31, 2015 at 01:24 PM 0
Share

There are no public variables in any of my classes (i believe they are evil)

avatar image Pangamini · Mar 31, 2015 at 02:21 PM 0
Share

Even if i am adding no new classes, or modifying any monoBehaviours, the number of errors increases as i work.. it now takes tens of seconds just to print them. I don't understand why I can't have my classes not deriving from Unity.Object without the engine going nuts... this happened when i upgraded from 4.6.1 and happens on all 5.xs i tested too

avatar image Glurth · Mar 31, 2015 at 02:39 PM 0
Share

ok, quick test. Create a new scene, in the same project, and open it in the editor. Do the errors continue on this blank scene? If so, hmm, that IS odd. If not, that implies you are mistaken, and SO$$anonymous$$ETHING in your (not empty) scene is attempting to serialize those classes.

There are no public variables in any of my classes

So how do you access their data? Get/Set accessors?

I don't understand why I can't have my classes not deriving from Unity.Object

You certainly SHOULD be able to use classes not deriving from unity.object without stuff going nutz, I know I do.
avatar image Pangamini · Mar 31, 2015 at 02:41 PM 0
Share

The same happens with the empty scene and all my custom editor windows closed (default layout). And yes, i use properties for everything

Show more comments

1 Reply

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

Answer by RobGraat · Apr 08, 2015 at 09:05 AM

From: 4.5 - Serialization Depth

What 4.5 highlighted is that private and protected field, while not saved on disk, are still processed by the serialization pipeline. So while you think your public field does not offer any chances of dependency loops, your private/protected fields might, and the Editor doesn't like that one bit.

FIX

Obviously, the best fix would be for Unity to perform serialization as they advertised and ignore private/protected fields. However, for now, the workaround found was to manually flag your non-serialized field with the [NonSerialized] attribute.

Comment
Add comment · Show 4 · 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 Bunny83 · Apr 08, 2015 at 10:07 AM 1
Share

Just want to add that Unity, when it comes to "normal" serialization, doesn't automatically process private and / or protected variables.

Only the Unity editor does this to allow an assembly reload at runtime. Actually that feature was flawed from the very beginning since static fields aren't saved / restored, so most singleton stuff will mess up anyways. Also if there are non serializable classes those will be lost too at assembly reload.

Usually Unity shouldn't touch instances which aren't serializable. However in your example error message we can see that the offending classname is "O$$anonymous$$.$$anonymous$$ath::Transform" it might interfere with "UnityEngine.Transform" since the class name is the same.

Yes, yes, Unity now supports namespaces, but actually, no ^^.

avatar image Pangamini · Apr 08, 2015 at 10:10 AM 0
Share

Thanks. I tried, and the name of the class is not causing the problem, seen in the example above.

It's good to hear that unity tries to improve assembly reloading, but still I don't believe i will ever rely on it's ability to update scripts during the playmode and keep everything valid.

avatar image MaxEden · Apr 08, 2015 at 10:26 AM 0
Share

"normal" serialization, doesn't automatically process private and / or protected variables.

Well, it shouldn't, but sometimes it did. Thank god, there is serialization as text, where you can fix it manually.
avatar image Pangamini · Apr 08, 2015 at 10:53 AM 0
Share

Still, it would be very useful if unity at least told me which object/class causes the error. This way i have no idea!

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

UnityScript How To Deserialize? 1 Answer

URGENT - Serializing error The type of argument is not primitive 0 Answers

Error Using DataContractSerializer 1 Answer

How to serialize a gameobject using binaryformatter? 0 Answers

how do i port from unity3d to windows phone 8 4 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