Very smart… I admit to being too lazy most of the time… BUT… occasionally I have even stuck some #if UNITY_EDITOR
code in my Reset()s to actually go digging for actual disk assets!!!
Since you mention it, I think I will try to make that a step from now on.
For others wondering what Lurk and I are on about…
Serialized properties in Unity are initialized as a cascade of possible values, each subsequent value (if present) overwriting the previous value:
-
what the class constructor makes (either default(T) or else field initializers, eg “what’s in your code”)
-
what is saved with the prefab
-
what is saved with the prefab override(s)/variant(s)
-
what is saved in the scene and not applied to the prefab
-
what is changed in Awake(), Start(), or even later etc.
Make sure you only initialize things at ONE of the above levels, or if necessary, at levels that you specifically understand in your use case. Otherwise errors will seem very mysterious.
Here’s the official discussion: Serialization in Unity
Field initializers versus using Reset()
function and Unity serialization: