- Home /
Previous scene's canvas stays on screen
On my project when I have load a new scene with
SceneManager.LoadScene("Preview",LoadSceneMode.Single);
the canvas from previous scene stays on scene and the canvas on the new scene (Preview in this case) is in front of it and the Game Objects I have created in a scripts Start() is cannot be seen. I don't want the previous scene's canvas to be seen at all, but couldn't manage to do that. How can I fix this?
Thanks in advance.
Do you have any component calling DontDestroyOnLoad
on this canvas?
Answer by L4t · Feb 22, 2021 at 09:40 PM
Seems like your canvas is DontDestroyOnLoad.
Here is a thread discussing undoing DontDestroyOnLoad: https://answers.unity.com/questions/1491238/undo-dontdestroyonload.html
One option could be attaching a script something like this to the object you don't want to carry on to the next scene:
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour
{
private void OnLevelWasLoaded(int level)
{
Destroy(gameObject);
}
}
I haven't tried the code but it should destroy what ever object the script is attached to when you change the scene.
Your answer
![](https://koobas.hobune.stream/wayback/20220613025413im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to find UI in code c# (button, Panel etc) 2 Answers
UI is invisible 1 Answer
Issues rotating a UI image while the canvas is parented to the Main Camera 0 Answers
UI image showing up "behind" player. 2 Answers
Masking GameObject in Canvas 1 Answer