List is not null with [SerializeField]

Hi there,

I just had a very weird behaviour with one of my Lists. I need to know if one of my lists is null. So I test that with

void Start()
{
    Debug.Log(myList == null);
}

When I define my variable like this:

[SerializeField] List<MyObjects> myList = null;

The console output is: False

But when I define my variale like this:

List<MyObjects> myList = null;

The console output is: True

That’s really dangerous and confusing, any idea why that is the case?

When you go to the editor, those objects which have attached your script modify that list and convert it to an empty list. Not null, list of size 0.

As @Bunny83 pointed out , Serialization does not support null values.