SceneManager 5.5.2f1 temporary switch - how to disable MainScene?

Dear Programmers, :wink:
I’m testing the new SceneManager possibilities to use multiple scenes at the “same time”.
(Yet I was putting everything into one scene, with lots of booleans to decide what to show runtime.)

My goal is to KEEP the “Main-scene”, and show other scenes just temporary.
The problem is: since I’m not unloading the main scene >
HOW can I make it invisible and UN-interactable ? There is no such thing as MainScene.SetActive(false);

Tried to disable the Main Camera, but it keeps being active! (Maybe a BUG?)
I can turn off only from Unity Inspector by hand.

// *** MainProgram.cs
public static class KAMERA_ {
    public static Camera MainKam;
    public static Camera NoteKam;
... }


void Start () {
...
    KAMERA_.NoteKam = GameObject.Find("Note Camera" ).GetComponent<Camera>();
    KAMERA_.MainKam = GameObject.Find("MainSceneCam").GetComponent<Camera>();
}

// *** MenuPanel.cs with lots of buttons
void Update() {
...
    const string ststxt = "StatisticalScene";
   if ( !SceneManager.GetActiveScene().name.Equals(ststxt)) {
       var sc = SceneManager.GetSceneByName(ststxt);
       if (sc != null) if (sc.isLoaded) {
           KAMERA_.MainKam.enabled = false; // >> nothing happens
           KAMERA_.NoteKam.enabled = false;
           OtherObjects.SetActive(false); // This works fine
           SceneManager.SetActiveScene(sc);
           ...
       }
   }

   if (GUI.Button(new Rect(w * 0.49f, h / 1.45f, w * 0.20f, h * 0.15f), "Show\nStatistics")) {
       SceneManager.LoadScene (ststxt, LoadSceneMode.Additive);
   }
}

Can someone help me please ??? THANKS! :smile:

I’ve thought setting the Main-monobehavior script’s ENABLE property to FALSE would be an easy-solution…
But I can not call this from outside the main class to re-enable it!

MyMainSceneScript.enable = true; //<< ERROR, not static public property

… also tried to create a static void around it:

public static void ENABL(bool e) {
   this.enabled = e; // << error: can not use "this" in static...
}

So I’m out of ideas. :frowning:

To clarify, when you say that you want the scene off, you just want one script off?
If you reference the script you want off, outside of the main class, you should be able to disable/enable it by reference.
Another option is to keep a static Instance copy of the MainSceneScript (singleton), since you always have it loaded. Then , you can access that variable , as well as it’s enabled value. Hope that makes sense. Let me know if that works/was all you needed. :slight_smile:

Thanks for answering! By “turn OFF” the main-scene I mean:

  • disable visually
  • disable update + interactivity

How do I create a reference to MainSceneScript?

“keep a static Instance copy of the MainSceneScript”

  • Sorry, I don’t understand. Can you link an example?

Okay, well the visual part would be another step, I suppose, but for the main script…

// inside MyMainScript
public static MyMainScript Instance;

void Awake(){
Instance = this;
} // there is code to prevent this spawning, again, but your situation is quite unique in that this script/object is never destroyed, reloaded, etc.. so this is enough.

// in some other script, when you want to enable/disable that script:
MyMainScript.Instance.enabled = true; // or false
// the other concept would have been, in other scripts where you want to reference it...
MyMainScript myMainScript;
// then you'd either have to link it in via the inspector, or FindItByTag or something similar. but that variable could be used for the same purpose..

Hope that makes sense.

Coool! :slight_smile: Now I understand what you mean. Thank you ! I’ll try those…

Any idea, why:
KAMERA_.MainKam.enabled = false;
not disabling the camera? (Can be disabled only from the inspector at runtime )

Is that the same thing as Camera.main.enabled = false? :slight_smile:
Had never tried that before, so I just ran a test and from a button click I turned off the camera.
If you have a few different cameras, maybe have each scene script turn its own off/on with a direct reference.