#Earliest executable code possible ?
1 messages · Page 1 of 1 (latest)
maybe in a static constructor
although I think that only gets invoked the first time you interact with the class
"It is called automatically before the first instance is created or any static members are referenced"
unclear
hmmm. Thanks for the suggestion! Will test it.
Could use RuntimeInitializeOnLoadMethodAttribute.
https://docs.unity3d.com/ScriptReference/RuntimeInitializeOnLoadMethodAttribute-ctor.html
@scarlet crater Yeah, I saw that... What confused me about it is in the documentation for RuntimeInitializeOnLoadMethodAttribute, it says:
This is after the Awake method has been invoked.
https://docs.unity3d.com/ScriptReference/RuntimeInitializeOnLoadMethodAttribute.html
For an Awake method to be invoked, I assume there would need to be a MonoBehaviour, which implies that there would need to be a scene already loaded. I'm not sure. I find the verbiage used a little confusing.
Yeah, I saw that too. You'd think that before the scene or the splash screen is loaded, none of the Awakes would be invoked, right? But then it explicitly mentions this in the documentation:
Methods marked [RuntimeInitializeOnLoadMethod] are invoked after the game has been loaded. This is after the Awake method has been invoked.
Does that imply that Awake is called on MonoBehaviours before the scene they are contained within is even loaded?
@scarlet crater
This most refer to the default constructor without the parameter.
Ahhhh, of course. Sorry for the dumb line of questioning.
The best way you know is to test it.
@scarlet crater
If you're curious, here are the results using System.Diagnostics.Stopwatch.
So basically, static constructor seems to be the first point at which you can start executing code.
Stopwatch started in static constructor
SubsystemRegistration completed in 00:00:00.00
AfterAssembliesLoaded completed in 00:00:00.00
BeforeSplashScreen completed in 00:00:00.06
BeforeSceneLoaded completed in 00:00:05.07
First scene Awake completed in 00:00:00.06
First scene Start completed in 00:00:00.52