- Home /
This question was
closed Jun 22, 2020 at 08:35 PM by
wasssim for the following reason:
Too subjective and argumentative
Question by
wasssim · Jun 21, 2020 at 07:28 PM ·
c#uicanvasdontdestroyonloadchild object
How to DontDestroyOnLoad a specific ui of a canvas?
Hello, I want to dontdestroyonload the achievments on my project, however we all know that we have to use dontdestroyonload on the entire canvas to dont destroy it's component. The problem is that my canvas has too many things in it and if I keep all the things which are in it, the next scene I want to load does not even load..
How can I deal with this problem? you can see below my script and a screenshot:
public GameObject dontDestroyObj;
public static MenuScene Instance { get; private set; }
private void Awake()
{
if(Instance == null)
{
Instance = this;
DontDestroyOnLoad(gameObject);
DontDestroyOnLoad(dontDestroyObj);
}
else
{
Destroy(gameObject);
Destroy(dontDestroyObj);
}
Scene currentScene = SceneManager.GetActiveScene();
string sceneName = currentScene.name;
if (sceneName == "Scene 1 (main menu)" && dontDestroyObj!= null)
{
dontDestroyObj.SetActive(true);
}
else
{
dontDestroyObj.SetActive(false);
}
}
and here is a screen:
This is my canvas and the highlight part is the only thing I want to keep
Thank you for your ideas!
erreur.png
(34.0 kB)
Comment
Answer by Zuries · Jun 22, 2020 at 10:01 AM
Can't you make a separate canvas for the things you want to keep?
Follow this Question
Related Questions
How to change anchor? 1 Answer
Quick Question on UI Text Alignment 1 Answer