Warning: Serialization depth limit 10 exceeded

Stormi

Member
Hi Santiago,

I am not sure if this is UIS related or general Unity stuff (wasn't able to find the cause until now), so I thought, I'd at least ask if you got an idea where these warnings could come from suddenly:

Serialization depth limit 10 exceeded at 'Opsive.Shared.Utility::Serialization.m_ValueHashes'. There may be an object composition cycle in one or more of your serialized classes.

Serialization hierarchy:
11: Opsive.Shared.Utility::Serialization.m_ValueHashes
10: Opsive.UltimateInventorySystem.Core.AttributeSystem::AttributeCollection.m_AttributeCollectionData

Serialization depth limit 10 exceeded at 'Opsive.UltimateInventorySystem.Core.AttributeSystem::AttributeCollection.m_AttributeCollectionData'. There may be an object composition cycle in one or more of your serialized classes.

Serialization hierarchy:
11: Opsive.UltimateInventorySystem.Core.AttributeSystem::AttributeCollection.m_AttributeCollectionData
 
This warning appears when there is a potential infinite loop in the serialized data. We set a limit of depth 10 to reduce the potential of making your computer explode. Note that Unity does the same with their serializer.

This can happen if you added a custom attribute type and that custom type references itself.

Example:

Code:
[Serializable]
public class ThisIsBadClass{
    [SerializeField] private ThisIsBadClass m_ThisIsBad;
    [SerializeField] private int m_ID;
}

The class above will want to serialize itself infinitely until something stops it.

So make sure to go through all you attribute types you added recently and look inside to see if you find anything.
(Note that we can nest items using some clever tricks but to a certain limit... for saving for example we limit the nested items to 1 depth)
 
What I find weird though is, that even if I remove all my own scripts from the project for test purposes, the warning messages still appear, so I am a bit lost in regards to where else I should look.

Also tried to reset the "Types" under Unit Options to default with no changes to the warning messages.

Sometimes I also get this error messages, in case that helps you with having an idea where the problem could come up:

Recursive Serialization is not supported. You can't dereference a PPtr while loading. (Constructors of C# classes may not load objects either. See stacktrace.)

Recursive Serialization is not supported. You can't dereference a PPtr while loading. (Constructors of C# classes may not load objects either. See stacktrace.)
UnityEditor.AssetDatabase:LoadAssetAtPath(String)
Opsive.UltimateInventorySystem.Editor.Managers.UIDesigner.UIDesignerSchemaSetupSubMenu:FetchSchemas() (at Assets/Opsive/UltimateInventorySystem/Editor/Managers/UIDesigner/SetupDesigner.cs:311)
Opsive.UltimateInventorySystem.Editor.Managers.UIDesigner.UIDesignerSchemaSetupSubMenu:.ctor() (at Assets/Opsive/UltimateInventorySystem/Editor/Managers/UIDesigner/SetupDesigner.cs:158)
Opsive.UltimateInventorySystem.Editor.Managers.UIDesigner.SetupDesigner:.ctor() (at Assets/Opsive/UltimateInventorySystem/Editor/Managers/UIDesigner/SetupDesigner.cs:45)
Opsive.UltimateInventorySystem.Editor.Managers.UIDesigner.UIDesignerManager:BuildVisualElements() (at Assets/Opsive/UltimateInventorySystem/Editor/Managers/UIDesigner/UIDesignerManager.cs:105)
Opsive.UltimateInventorySystem.Editor.Managers.MainManagerWindow:OnEnable() (at Assets/Opsive/UltimateInventorySystem/Editor/Managers/MainManagerWindow.cs:280)
UnityEditor.EditorWindow:GetWindow(Boolean, String)
Opsive.UltimateInventorySystem.Editor.Managers.MainManagerWindow:ShowWindow() (at Assets/Opsive/UltimateInventorySystem/Editor/Managers/MainManagerWindow.cs:125)
Opsive.UltimateInventorySystem.Editor.Managers.MainManagerWindow:ShowItemCategoriesManagerWindow() (at Assets/Opsive/UltimateInventorySystem/Editor/Managers/MainManagerWindow.cs:136)


Also, this thread obviously was meant to be posted in "Questions". Sorry for that.
 
Last edited:
The second error seems to be a Unity only error within a prefab or a scriptable object which has a recursive serialization...Unfotunatly that error message doesn't helps us identify which prefab/scriptable object is is talking about (probably one in the designer schema or referenced by an object in the schema)

I'm afraid there isn't much I can do with the limited information. I would recommend you use a breakpoint just before the line where the error occurs. And check the object it is referencing. From there find that object in question in your projects and try to identify what component is causing the problem.
 
Thanks for trying to help. I'll focus for now on the "Depth limit" warnings, since they appear at every compile when loading unity or after saving a script as well as every time I start the game. The "Recursive Serialization" errors only appear once in a while, so maybe whatever causes the other issues is at least connected here.

Considering that "AttributeCollectionData" is mentioned in the warnings, I went into AttributeCollection.cs and put four Debug.Log in there just to start looking differently at it and to see what happens within the Serialize and Deserialize methods:

C#:
        /// <summary>
        /// Deserializes the attributes and stores them in the list and dictionary.
        /// </summary>
        /// <param name="force">Force the initialization.</param>
        protected void Deserialize(bool force)
        {
            if (m_Attributes != null && !force) { return; }

            if (m_AttributeCollectionData == null) {
                Debug.Log("1: " + m_AttributeCollectionData); // TEST ONLY
                if (m_Attributes == null) { m_Attributes = new ResizableArray<AttributeBase>(); }
                return;
            }

            m_Attributes = new ResizableArray<AttributeBase>();
            m_Attributes.Initialize(m_AttributeCollectionData.Length);
            for (int i = 0; i < m_AttributeCollectionData.Length; i++) {
                Debug.Log("2: " + m_AttributeCollectionData[i]); // TEST ONLY
                var attribute = m_AttributeCollectionData[i].DeserializeFields(MemberVisibility.Public) as AttributeBase;
                if (attribute == null) { continue; }
                if (ContainsAttribute(attribute.Name)) {
                    Debug.LogError($"The attribute collection for {GetAttachedObject()} already has an attribute with name: {attribute.Name}.");
                    continue;
                }
                attribute.AddedTo(this);
                attribute.Deserialize();
                m_Attributes.Add(attribute);
            }
        }

        /// <summary>
        /// Serializes the attributes in the collection by adding the attributes inside AttributeCollectionData.
        /// </summary>
        public void Serialize()
        {
            if (m_Attributes == null) {
                Debug.Log("3" + m_AttributeCollectionData); // TEST ONLY
                m_AttributeCollectionData = Serialization.Serialize<AttributeBase>(new List<AttributeBase>());
                return;
            }

            var attributes = new List<AttributeBase>();
            for (int i = 0; i < m_Attributes.Count; i++) {
                Debug.Log("4" + m_Attributes[i]); // TEST ONLY
                var attribute = m_Attributes[i];
                attribute.Serialize();
                attributes.Add(attribute);
            }

            m_AttributeCollectionData = Serialization.Serialize<AttributeBase>(attributes);
        }

Here you can see how often the individual debug.log entries were printed. This is right after loading into the game:

1611344781500.png

Does the amount of executions for Deserialize with zero Serialize seem right to you? If not, any idea where to go further from here? Obviously I am on a fishing expedition in your code right now to see what the heck is causing the errors. Of course, I'm not saying your code is faulty - just trying to figure out what is happening and where to look for the root cause as I am flying completely blind here right now :)
 
The first warning you mentioned in the very first post should have a stack trace. you should be able to see the lines of code that triggered the warning.
Try to debug those exact lines instead of trying to debug the entire serialize/deserialize system for attributes.
 
Top