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 @Tor Esa Vestergaard 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. Log in to comment