How to avoid cross-scenes reference errors when testing a single one in Unity ?

Hi everyone,

In my Unity learning project, i’m using references to the UI object present in the bootstrap menu (Game jam menu template in my case) in other scenes. For instance in the game or tutorial scene (i tweaked the template to support more scenes to learn a bit more…), when i want to reuse the music or scene management scripts :

public class ExitTutorial : MonoBehaviour {
    private StartOptions startScript;

    void Awake () {
        startScript = GameObject.FindGameObjectWithTag("UI").GetComponent<StartOptions>();
    }
....
}

Everything’s ok when i test a build, or if i load the Bootstrap menu in Unity before launching the built-in game test, but if i launch the test directly from my tutorial scene, i get the NullReference error.
I understand why, but i wonder how i can test this single scene when i’m working on it without the error

I found 2 solution but i’m not 100% satisfied with them

    1. Encapsuate this code with #if UNITY_EDITOR, but in that case i can’t test the references when i launch the boostrap scene & access another one from the game view
    1. Deactivate “Error pause” in the console, but i’m sure it’s not a good habit and i’ll end up missing important stuff…

I’m sure i’m just missing the proper way to do it :slight_smile:
Thanks in advance

Silly me…

if(GameObject.Find ("UI"))
{
      Debug.Log ("No need to instantiate UI, can use the references");
}
else Debug.Log ("Doesn't exist, instantiate UI prefab or don't use the UI related references");