SceneManager does not work on Build


I have a menu ingame that have a button to bring back to Main Menu. It works pretty fine in the editor, but on the Build it just doesn’t work.

	public void BackToMainMenu(){
		boardManager.GetComponent<Board_Manager>().SavingUpdate ();
		Data_Store.SaveGame (boardManager.GetComponent<Board_Manager>().stateForSaving);
		SceneManager.LoadScene (0);

On the developer build I receive this message:

What can be happening here?

The menu is a Prefab that is instantiated when the player clicks the Menu button.

Hello there,

Try clicking on the error message: what does it say? Which line seems to be the problem? Maybe the error happens before the LoadScene call…


To help debug in a dev build, you can put Debug.LogError() in between your lines, to know which ones get triggered and which ones don’t. It helps finding a solution more efficiently!


Otherwise, try opening your Build Settings (Ctrl + Shift + B or File > Build Settings). Do you actually have a scene set at index 0? If not, click on the scene that you want as your Main Menu scene. The index number will show up on the left of the scene name.

Hope that helps!



Nevermind. The problem was with the SaveGame code that was being called before the LoadScene.

It just happened that the way I set the validations for the SaveGame was working on editor, but not on Build. When all the positions were filled (no null gameObject reference) the SaveGame worked, and thus the button worked too.

I’ll close this thread, then. Thanks!