Reputation: 3812
at first, my most important research for this topic:
https://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager.LoadScene.html
https://docs.unity3d.com/ScriptReference/SceneManagement.LoadSceneMode.Additive.html
When I start my game from the main menu I get into the "Ingame" scene. The ingame scene got an ingame menu with some buttons. I can click an "Options" button there.
So from the main menu I start the game by this method:
public void StartGame()
{
LoadScene("Ingame", LoadSceneMode.Single); // Load the main scene of the game
}
So when I open up my ingame menu and click on the options button I call this method
public void LoadOptions()
{
LoadScene("Options", LoadSceneMode.Additive); // Don't destroy the game and load the options menu
}
This works fine, because it doesn't destroy the ingame scene. But the problem is, that all objects are kept to the options scene. That is not, what I have expected.
How can I get into the options scene without my ingame objects and get back to the ingame scene when finishing the options?
Thanks :)
Upvotes: 1
Views: 2354
Reputation: 6693
Once you are done with your Options scene, you can change your active scene back to your game and unload the menu scene. It will look something like this.
Scene gameScene = SceneManager.GetSceneByName("Ingame");
SceneManager.SetActiveScene(gameScene);
SceneManager.UnloadSceneAsync("Options");
Upvotes: 2