Serialization depth warning bug

Hey guys, this may be a bug? Not sure.

If you use

[Serializable]

On a class and then hold a reference to another class that is serializable but add the nonserializable to it like so…

[NonSerialized] public Scene scene;

You still get the serialization depth warning. I feel like if you add the [NonSerialized] to it then you shouldn’t get the warning.

Can you post more example code and the warning in full? It’s hard to say with little context.

The serialisation depth warning only really comes up with recursive or cyclical references are in play. One class having an instance to another class, where no cyclical references are present shouldn’t be throwing this warning.

1 Like

Ya its easy to do, just create two classes that reference each other.

[Serializable]
public class Bar { 
    public Foo foo;
}

[Serializable]
public class Foo {
    public Bar bar;
}

But I think if you set one to nonserializable then it shouldn’t give you the warning.

[NonSerialized] public Bar bar;

I mean when I replicate that, adding the [System.NonSerialized], I don’t get the warning.

What version of Unity are you on? This was testing on 2021.3.33f1, so not the most up to date.

1 Like