2 Classes with instances of each other cause infinite recursion

Issue #272 resolved
ElectroMantis created an issue

If you have two classes, (ClassA and ClassB) and they both have an instance of each other, the Odin inspector tries to create a "default" non null value recursively until the editor crashes.

using System.Collections.Generic;
using UnityEngine;

public class classBug : MonoBehaviour {
    public List<classA> classList;
}

[System.Serializable]
public class classA {
    public classB instance;
}

[System.Serializable]
public class classB {
    public classA instance;
}

Explanation from @TorVestergaard on discord -

What's happening is that Odin guesses that the value is serialized by Unity, and so it creates a "default" non null value and populates that value with values and so on recursively. We have safety cutoffs that prevent an infinite recursion and Unity will shout at you so we figured that'd be alright. But apparently in some cases too many values are created and drawing that much data just crashes Unity for some reason or other. We'll need to lower the limit and make our cycle detection more sophisticated I suppose.

Comments (1)

  1. Tor Esa Vestergaard

    This issue has been resolved in patch 1.0.6.0, which is going through final testing and dropping very soon now. The provided code example in the issue now results in the following image:

    SF19nidERl6x5VaujMo9Rw.png

  2. Log in to comment