Given the code:
(CreateAssetMenu(fileName = "newGameManagerInstance", menuName = "Game/Game Manager Instance"))
public class GameManagerSO : ScriptableObject
{
private GameManager instance;
public GameManager Instance { get { return instance; } set { instance = value; } }
private void Awake()
{
Debug.Log("1");
}
private void OnEnable()
{
Debug.Log("2");
}
private void OnDisable()
{
Debug.Log("3");
}
private void OnDestroy()
{
Debug.Log("4");
}
}
I have two questions. 1) Why the output in console when I enter play mode is "3" and then "2"? Shouldn’t OnDisable
be executed after OnEnable
? And 2) I’m using this scriptable object to hold an object reference only (I don’t have the need to serialize the object, it’s just a handy way I found to pass that reference through scenes without committing to singletons); can I code all initialization code for the object in OnEnable
method? Can I assume it will always execute before any MonoBehaviour
read it?
Also