Game freezes after button is clicked to switch scenes

Hello,

I recently started 2D mobile development on Unity and don’t know a whole lot about it as of yet (learning as I go). For the most part everything has been going fine, but there is one error I have come across that I can not find out at all.

When I run the game, its starts up fine and everything loads properly, but as soon as I swap scenes a few times using the buttons handling onClick(), it causes the app to freeze.

These are the buttons I use to switch scenes, which are located on each scene:

89597-toimport.png

I have a small script setup for switching at the moment (I know it can be simplified to a single function and little amount of variables, this is just to help myself with referencing)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class SceneControl : MonoBehaviour {

	public void dungeonClick () {
		SceneManager.LoadScene ("DungeonScreen", LoadSceneMode.Additive);
			SceneManager.UnloadSceneAsync ("TavernScreen");
			SceneManager.UnloadSceneAsync ("ActivitiesScreen");
	}

	public void tavernClick () {
		SceneManager.LoadScene ("TavernScreen", LoadSceneMode.Additive);
			SceneManager.UnloadSceneAsync ("DungeonScreen");
			SceneManager.UnloadSceneAsync ("ActivitiesScreen");
	}

	public void activitiesClick () {
		SceneManager.LoadScene ("ActivitiesScreen", LoadSceneMode.Additive);
			SceneManager.UnloadSceneAsync ("DungeonScreen");
			SceneManager.UnloadSceneAsync ("TavernScreen");
	}
}

The app originally froze when I first clicked to switch scenes, and I don’t know what I did to lengthen the amount of time before it freezes. It went from first switch of a scene to four. I have tried looking through google for the longest time for a solution but all I can find is about LoadScene destroying the previous scene and creating the new scene.

I am separately unloading the other scenes because when I left the LoadScene normally, it would hang instantly on the button press after switching the scenes. When I tried this way it would allow switching a few times before it froze on a scene again.

I do have the C# Script in each scene connected to the canvases. I don’t know what else may be helpful to understanding the problem I am having, but the error may be something very simple that I haven’t realized for the past hours or so that maybe someone knows.

Managed to figure out a way to load and unload certain scenes using a master scene without it causing any errors.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class ButtonControl : MonoBehaviour {

	public void dungeonClick () {
		SceneManager.UnloadSceneAsync ("TavernScreen");
		SceneManager.LoadScene ("DungeonScreen", LoadSceneMode.Additive);
	}

	public void tavernClick () {
		SceneManager.UnloadSceneAsync ("DungeonScreen");
		SceneManager.LoadScene ("TavernScreen", LoadSceneMode.Additive);
	}
}

Thank you @hexagonius for your help overall, got me thinking of a better way to load the scenes. Truly appreciated :smiley: and surprised I didn’t think of doing this earlier.