List returns NullReferenceException, but when it's visible in the Inspector it works perfectly ???

Hi fellow developers

I have a weird issue. I have a collection of lists, that keeps track of my enemies in my game. Whenever I play the game, with my lists shown in the Inspector sidepanel, they work as intended. But when my inspector is showing anything else, the lists give me NullReferenceExceptions.

Is this a bug or what could cause this behavior?

The inspector will automatically create an instance of a List or array when viewed. At least any Array or List that is serialized. If you fill / create the list dynamically at runtime you have to create the list manually.

You should inlude the declaration of your List variable(s). Also the spot where you get the NullReferenceException and maybe the part where you initialize your list(s) is you even do this.