I’m working with C# scripts, and I’ve come across a null check for an item that’s set from the Unity Editor. This leads me to the question, when do these attributes get set? Or, more specifically, where in the lifetime of a class that’s instantiated from Unity Editor, does Unity set the values of its attributes? I would assume that it’s sometime after the constructor. Yet, other than that, I’ve got no clue.
Bear in mind that Unity usually doesn’t want you calling constructors directly – not for components that it manages, anyway. When an object is loaded from disk, as part of a scene or prefab, Unity will populate all of the serialized data during that load.
Under normal circumstances, that means that all serialized fields will be populated “immediately”, before you can check any of their values.
if you go around calling your own constructors, or initializing components from scratch, then you may need to set up some of the data on your own.