- Home /
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex); is working badly
When i start my game, I'm in the main menu. When i press play button, game menu dissapears (as i want) and game starts.. Then i want to go back to the main menu again. I click the button to go to the main menu. If i get there with SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
.. the menu just freezes and i must to restart whole game to play again.
This loads the current scene, not the menu scene. Just use the direct scene name of your menu.
Scene$$anonymous$$anager.LoadScene("$$anonymous$$ain$$anonymous$$enuorwhatever");
1) I wanted to load current scene 2) Your code does the same
Answer by Legend_Bacon · Feb 12, 2018 at 05:33 PM
Hello there,
The line you posted in your original post reloads the scene you're currently in. If this is what you want, then the problem may come from somewhere else. Maybe you're not properly clearing or resetting static variables, events or classes?
Also, check that your build settings (ctrl + shift + b) are setup properly. I think that error would pop up if your main menu scene doesn't have an index assigned. Might be wrong, but might as well check.
Hope that helps!
Cheers,
~LegendBacon
hi.. thx for comment... i dont have enought time now so i will look for these issues tommorow. Anyway thx... I'll write you tommorow.
I've checked everything now.. I have even cleared all static variables. But still freezes when i load the scene... but the editor is running while the "Game" is freezed.
I see... Have you checked the timescale (edit -> project settings -> time) ? You might be setting it to 0 by accident somewhere. Other than that, I am really not sure.
You should try reproducing this with the bare $$anonymous$$imum in a brand new project, and see if it freezes still. If not, then something somewhere is wrong with your project.
Sorry I can't help more.
Cheers,
~LegendBacon
You were right i had the Time.timeScale badly.. but it still freezes.. Ty for help i did it in other way to make it work.