- Home /
Serialization depth limit exceeded
Has anyone come across this since upgrading to 4.5?
Serialization depth limit exceeded at '::LogicStatements'. There may be an object composition cycle in one or more of your serialized classes.
I'm guessing it's one of those hiddden errors 4.3, et al. cleaned up for you.
The error is not stopping the build, just shows up constantly as an error in the editor.
I'm getting the same error after my upgrade to 4.5 I am very interested in knowing what is causing it and if there is a workaround. I wonder if any of my (or your) assets may be causing it.
Hello. I am getting these error reports on classes that don't even derive from Unity class, nor they use the unity serialization... It's like unity picks random classes from my managed DLLs and prints this..
Answer by rutter · Jun 12, 2014 at 11:35 PM
Big forum thread about the issue, which includes discussion of the bug and suggested workarounds.
Answer by turbanov · Nov 14, 2017 at 01:44 PM
When working with serialized objects (no matter engine or framework) you should always consider unfolding hierarchies into linear arrays (lists). It is enough for child elements to have an index for their parents (since references of non-behavior types are not serialized at all). You can then recreate the hierarchies in your OnEnable
code. Just make sure, that both children arrays and possible links to parents are prefixed with [System.NonSerialized]
.
You should do so in Unity for one more reason. The engine doesn't seem to save information about types for properties past level 1, so you will have enums displayed as integers for child elements. be careful.
Your first part is correct. However your last point about enums i can't reproduce. Can you actually create a case that reproduces this behaviour?
ps: The engine doesn't save any type information for custom serializable classes. That's the reason why it does not support polymorphism for such classes. "Fields" of a serialized class instance are always serialized based on the field type. The only exception are classes derived from UnityEngine.Object. Those are / need to be serialized on their own and Unity can actually serialize a "true" reference. In this case you can use polymorphism.
Answer by morbidcamel · Feb 06, 2015 at 03:39 AM
Hi Guys,
I have a simple class which I use to build my game menu. This error never happened and sure I go about 4 levels down but I think there should be a way to control the "maxlevels" or something - also I can't see where recursion might occur from an editor's point of view
[Serializable]
public class GameMenuItem
{
#region Menu Properties
public string name;
public string pauseMenuName;
public MenuState state;
public string key;
public GameMenuItem[] subMenuItems;
internal Vector2 position;
internal int level;
internal bool isSelected;
[NonSerialized]
internal object data;
internal int selectedIndex = -1;
#endregion
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613151104im_/https://answers.unity.com/themes/thub/images/avi.jpg)