unity data_error ai_generated true

Serialization depth limit exceeded. Consider increasing the Serialization Depth Limit in Project Settings.

ID: unity/scriptableobject-serialization-layout-change

Also available as: JSON · Markdown · 中文
90%Fix Rate
85%Confidence
1Evidence
2023-05-20First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
Unity 2022.3 active
Unity 2023.2 active
Unity 2021.3 active

Root Cause

A ScriptableObject or MonoBehaviour has a deeply nested reference chain (more than 7 levels) that exceeds Unity's default serialization depth.

generic

中文

ScriptableObject 或 MonoBehaviour 具有深度嵌套的引用链(超过 7 层),超出 Unity 的默认序列化深度。

Official Documentation

https://docs.unity3d.com/Manual/script-Serialization.html

Workarounds

  1. 85% success Restructure your data to avoid deep nesting: flatten references by using IDs or asset references instead of direct object references. Example: replace `public List<ChildData> children;` with `public List<string> childGuids;` and load via Resources.Load.
    Restructure your data to avoid deep nesting: flatten references by using IDs or asset references instead of direct object references. Example: replace `public List<ChildData> children;` with `public List<string> childGuids;` and load via Resources.Load.
  2. 90% success Increase the serialization depth limit in Edit > Project Settings > Editor > Serialization Depth Limit to a higher value (e.g., 10 or 15).
    Increase the serialization depth limit in Edit > Project Settings > Editor > Serialization Depth Limit to a higher value (e.g., 10 or 15).
  3. 75% success Use `[System.NonSerialized]` on intermediate fields that don't need to persist, breaking the serialization chain.
    Use `[System.NonSerialized]` on intermediate fields that don't need to persist, breaking the serialization chain.

中文步骤

  1. Restructure your data to avoid deep nesting: flatten references by using IDs or asset references instead of direct object references. Example: replace `public List<ChildData> children;` with `public List<string> childGuids;` and load via Resources.Load.
  2. Increase the serialization depth limit in Edit > Project Settings > Editor > Serialization Depth Limit to a higher value (e.g., 10 or 15).
  3. Use `[System.NonSerialized]` on intermediate fields that don't need to persist, breaking the serialization chain.

Dead Ends

Common approaches that don't work:

  1. 30% fail

    Simply increasing the depth limit in Project Settings can mask the issue and lead to performance degradation from deep serialization.

  2. 50% fail

    Adding [SerializeReference] to fields does not reduce the depth; it only changes how references are stored.

  3. 70% fail

    Removing all nested objects breaks the data structure and loses functionality.