I use a prefab _AppStartup which is just an empty game object having a script AppStartup. Drag this in every scene and configure AppStartup to be executed as first like @maZZZu has stated.
AppStartup performs the following jobs:
- Global initialisation tasks when the app is started
- Switch to boot scene if have start an arbitrary scene in editor mode
Scene specific initialisation tasks
public class AppStartup : MonoBehaviour { const int bootSceneNo = 0; public static bool veryFirstCallInApp = true; void Awake () { if (veryFirstCallInApp) { ProgramBegins (); if (Application.loadedLevel != bootSceneNo) { // not the right scene, load boot scene and CU later Application.LoadLevel (bootSceneNo); // return as this scene will be destroyed now return; } else { // boot scene stuff goes here } } else { // stuff that must not be done in very first initialisation but afterwards } InitialiseScene (); veryFirstCallInApp = false; DestroyObject (gameObject); } void ProgramBegins() { // code executed only once when the app is started } void InitialiseScene () { // code to initialise scene } }
So all you have to do is drag this prefab in every scene manually and give it -100 or whatever in the script execution order. Especially when the project grows and relies on a predefined scene flow it will save you al lot time and hassle.
Awake()is called even before start but you will have to attach it to an emty gameObject in your every scene.