I am using a Scriptable Object architecture, and as part of it I need what Awake claims to do according to the documentation
“Awake is called as the
ScriptableObject script starts. This
happens as the game is launched and is
similar to MonoBehavior.Awake.”
This doesn’t seem to be true when playing. I have breakpoints on the
Awake function, and it gets called at random times in edit mode, and doesn’t get called when switching to play mode at all.
I tried using
OnEnable instead, combined with a check of
OnEnable gets called at random times in edit mode too, but at least this one does get called when starting play mode.
But here’s the funny thing:
private void OnEnable()
Debug.Log("The game is " + (Application.isPlaying ? "playing" : "not playing"));
OnEnable call right after pressing the play button,
Application.isPlaying is false, despite the game being in play mode. The above Debug log will print
The game is not playing. It seems that the
Application.isPlaying gets enabled after
OnEnable is called.
At this point I have run out of ideas of ways I could get some kind of function call when the game starts.