- Home /
Question by
Emancipate · Sep 18, 2021 at 02:34 PM ·
load scene
How do I prevent creating multiple instances of the same scene when reloading a scene?
public class Canvas_Control : MonoBehaviour {
private static Canvas_Control canvas_control_instance;
void Awake()
{
DontDestroyOnLoad(this.gameObject);
if (canvas_control_instance == null) {
canvas_control_instance = this;
} else {
Destroy(gameObject);
}
}
public void Retry() {
print("retry pressed");
print("Before: " + SceneManager.sceneCount);
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex, LoadSceneMode.Single);
print("After load: " + SceneManager.sceneCount);
}
// The above prints Before: 1 and After load: 2
public void Next() {
print("next pressed");
// do stuff
}
// Now Next() will be called twice for each currently loaded scene,
// but I'd like it to be called only once.
}
Comment
Answer by Emancipate · Oct 02, 2021 at 08:42 PM
This problem was solved after realizing that other scripts were adding multiple listeners to the same button.
Your answer
Follow this Question
Related Questions
Application.LoadLevel, Send me to the same Scene 5 Answers
Streaming parts of a level into the scene 0 Answers
Issue with adding a Loading Screen 1 Answer
Plz Need Help 1 Answer
Load new scene on object click 1 Answer