Scenemanager.setactivescene

hi All,
New to unity and hoping for advice. I been asking question related to this for a few weeks but don’t seem to be able to find an answer. I’d like to load a few scenes into memory at once and switch between them. Right now the best way I can find is to have a single scene, but load others to a different part of the scene using additive and the instantly switch view. However scene manager has the title function which seems to imply I can have different scenes loaded and set anyone to active. Problem is I can’t really find decent documentation or examples of how to do this. Can anyone explain how to use this or point me to a tutorial?
Thanks

Hi! Have you read this page? Unity - Manual: Work with multiple scenes in Unity

Hi Thanks for this. But I’ll be honest I can’t full follow that documentation. I appears to be referring to the Editor only.? Or perhaps but using the editor in this way when I build a game I can use scene swapping using the scenemanager class?

Sorry yes, I see now you meant in scripting, and that page doesn’t really give you much.

Is the function not working? Can you post your code? I don’t think we have any tutorials relating to this at the moment.

Thanks for the reply
I can’t post as I haven’t worked out how to get multiple scenes loaded at once to be able to use the set active. The documentation seems to say if you load another scene the then the running scene is destroyed, if you use additive it just drops into already created scene?
There seems to be no documentation on how to use these?

Hi,

You have misunderstood what Active Scene means: from what I understand, you think it means: What scene is being rendered and gets updated. But this is not the case. I don’t blame you, the docs are very slim in describing what the active scene is (and it can easily be confused with ‘active gameobject’). We are fixing this both in the manual and under Get/SetActiveScene API docs)
In the manual we state: “Set Active Scene: This allows you to specify which scene new Game Objects are created/instantiated in. There must always be one scene marked as the active scene”
So the active scene nothing more than that: a pointer to the scene where e.g calling: “var go = new GameObject()” will end up in. (Active scene also controls from what scene we use the Lighting settings for rendering and some other scene based settings).

What you can do to achieve what you want is using the GameObject.SetActive method to enable/disable the root game objects of the scenes you want to control.
So load all your scenes additively (so SceneManger will have a list of scenes) and then control what game objects are active.

Simple scripting tutorial here: Activating GameObjects - Unity Learn

Scene has GetRootGameObjects you can use to control the game objects of that scene (Unity - Scripting API: SceneManagement.Scene.GetRootGameObjects)

Hope this helps.

1 Like

@Mads-Nyholm there are 3 active: GO active, GO creation to active scene and finally allowSceneActivation active, how do you refer to them internally?

From my tests doing scene activation like you said still calls the loaded scene’s GO’s Awake(). I’ve tried getting a tighter control of the scene load with allowSceneActivation=false but when set to true after .progress reaches 0.9f (ref documentation) I don’t know how to avoid it from activating all the GOs before I can do an operation on them.

It would be great if scenes acted exactly like gameobjects. Do you plan on adding an async version of Instantiate(GameObject)? That would unify scene and GO in a rather dashing way.