- Home /
Uninstantiated list somehow instantiated at runtime.
I declare a list but don't instantiate it anywhere in the code, nor have I dragged anything into it in the inspector. When I print the list to console, it's instantiated. I expect it to be null, not instantiated. Even if I set it to null when declaring it, it's still instantiated at runtime, with size 0.
public List<myObj> myList = null;
void Start()
{
print(myList);
}
The only way it stays null is if I set it to null in Start(). Is this intended or a bug? And any way to have it stay null when declaring?
Answer by Llama_w_2Ls · Oct 18, 2021 at 06:30 AM
This is intended behaviour by the Unity Editor. Anything serializable is initialized at runtime, no matter if you called the constructor or not. Unity will call it, to draw it in the inspector.
Your answer
![](https://koobas.hobune.stream/wayback/20220613044312im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Getting Null From List 1 Answer
Null SerializedProperty SerializedObject upon Removal from list 1 Answer