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.

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

@piotrek_81 I’ve done all that but i haven’t said that i have transform in ScaleBack() function… and i get this error: error CS0120: An object reference is required to access non-static member `UnityEngine.Component.transform’ what to do with that m8. Thx for help anyway.
This is the question about the accessing non static member. - my question got rejected, but i can’t find answer to it.
And i would aprechiatte if you would help me with this question about Scenes as well. Ty m8.