- Home /
Keep some UI alive between scenes
I was planning to keep one UI element alive between scenes using DontDestroyOnLoad
but that is causing warnings and essentially not working. I wonder if I need to call DontDestroyOnLoad
on the canvas as well, and if that can cause issues since each scene has a canvas with different elements but there is this one in particular that I want to always keep alive.
I thought of having a new one for each scene, but the component has some state, and keeping that state alive seems easier than passing it around. How to deal with this?
Are you saying that you want to keep the UI while the other scene is loading, as in you want a loading screen that contains all of the UI. Or are you saying that you want the UI to transfer into your next scene?
That's a good point. $$anonymous$$y original question was how to keep it alive in each scene, not during the loading process, but now you really made me want to do that as well! Although it was not the original intent of the question, how would you go for that?
Answer by Keyo · Sep 20, 2016 at 03:41 AM
You have to call DontDestroyOnLoad
on the canvas as well if you want to preserve the UI element. As long as you set the Sort Order on the Canvas component correctly, it shouldn't pose an issue to have multiple UI canvas on the scene. If you have any additional questions as to how to implement it, let me know.
Cool, that makes a lot of sense. I will close the question as soon as I finish implementing it. Thanks!
In the end the trick was to call DontDestroyOnLoad
on the canvas that is not supposed to be destroyed, not on the UI element itself. Thanks for the help!
Your answer
![](https://koobas.hobune.stream/wayback/20220612093102im_/https://answers.unity.com/themes/thub/images/avi.jpg)