ScriptableObject Life Cycle [ Help ]
As from the doc https://docs.unity3d.com/ScriptReference/ScriptableObject.html
We have
Awake This function is called when the ScriptableObject script is started.
OnDestroy This function is called when the scriptable object will be destroyed.
OnDisable This function is called when the scriptable object goes out of scope.
OnEnable This function is called when the object is loaded.
OnValidate Editor-only function that Unity calls when the script is loaded or a value changes in the Inspector.
Reset Reset to default values.
With this one liners, I am having multiple confusions
Q1. Awake vs OnEnable
Does Awake here mean that it is called when I create the instance of the scriptable object,
for eg say: right click asset menu and create the instance ?
and OnEnable called when the scriptableObject is in the scene referenced by someone, and when I hit play and the scene runs, this is called ?
Q2. OnDisable vs OnDestroy
Does OnDisable called when it is derefenced by the game object in the scene referenced previously?
then how come OnDestroy, is it when I delete the ScriptableObject asset which I created using right Click create ..?
Q3. Is right clicking and creating scriptable object through Asset menu equivalent to Instance creation
Q4. Is it a bad practice to store a scriptable object in a scriptable object and so on.. ? As not done carefully, this will lead to multiple reference not found exceptions.
Q5. How is there a null reference, when you add a variable in a scriptable object which takes the exposed variable input done at inspector and converts it into a different variable type acting as a provider. for eg
//Inside Scriptable Object. This is exposed in the inspector and values are added in the inspector
[SerializeField] private SomeScriptableObjectType[] someValues = default;
//Another variable converts the above scriptableobject array into Dictionary OnEnable
readonly private Dictionary[SomeScriptableObjectType, int] dictSomeValues = new Dictionary[SomeScriptableObjectType, int];
private void OnEnable() {
InitializeDict();
}
void InitializeDict(){
//takes array and converts into Dictionary
dictSomeValues .Add ... //How come ArgumentNullException point here
}
public in GetValueFromDict(SomeScriptableObject k){
//It returns the value from the dictionary
}
// How come dictSomeValues can be null ??
// As the array which I have provided in the inspector are all valid values not having any null
Q6. Is Awake on Scriptableobject called before Monobehaviour OnAwake scriptable object or vice versa ?