i have 2 scene in my program, when click a button go to the second scene and when press home button (in the second scene) go to the previous scene, how can keep loaded the first scene? I tried the Scene Manager additive mode but it shows both scenes together, how can i do this?
2 Answers
If you want to keep the first scene loaded but hidden when the second scene is shown, it is not possible. But what you might want to try is to use SceneManager.LoadSceneAsync when you call the first scene from the second scene
I don't know the code but i am pretty sure you can find all the children of the scene make them setActive(false) and make everything hidden.
You need to use Scene Manager additive mode ofcourse.
-
I tried it but it's too complicated cause everytime i switch scene a new scene is created, i fix this loading the scenes at the same time and then use SetActivate to hidden the scene object when i click on button to switch scene, but i've encountered an issue, i cant pass first scene GameObjects to second scene, how can i do that? Commented Feb 28, 2021 at 22:50
-
@Michelo Loizzo if do you mean hold object state when changing scene you can use DontDestroyOnLoad. You can use it inside monobehaviour and everything in that monobehaviour and its gameobject will be saved for next scene.– SeLeCtRaCommented Mar 1, 2021 at 0:08
-
@SeLeCtRa no i didnt mean that, basically i had two scenes, each one with a button, the first scene has the goto scene2 and the scene 2 has goto scene1, what i wanted to do is basically go to scene2 do my stuff and then go back to scene1 without reload the scene so i can keep track of what i did before in scene1, same thing for scene 2. I found a solution that fits well, i deleted the second scene and put all the objects in a single scene then i disable and enable what objects i want. Commented Mar 1, 2021 at 2:37
-
The only problems i found with this solution is that one script (tooltip script thing) doesnt work properly, there's a weird bugs that i cant found out. Commented Mar 1, 2021 at 2:37
-
@MicheleLoizzo It looks like a temporary solution. But be aware, if you have many game objects in your scene 2, it will eat your RAM regardless, they are active or not. Why just you don't save values to a file then load it back when needed.– SeLeCtRaCommented Mar 1, 2021 at 9:07