Levels changing with UI best practice

I have a game with many levels. Hovewer on each level I have the SAME UI (buttons bause, health, ect.). Here is some BEST practice to realize scene loading with UI saving?

Levels as scenes? Or other way? I have realized loading levels from prefabs, but It was not best idea… I also can put same ui in each level…

Thanks!

“DontDestroyOnLoad” sounds like something that might interest you:

However, it will probably not just work like magic - you will have to be careful when UI elements refer to objects (e.g. the player) that DO get destroyed when loading a new level.

So you would probably have to have some kind of script that resets the UI after a level change, fixing references to objects, resetting values etc.

However, it may still be better than creating/copying the UI in every level scene, because then when you want to make changes, you will have to do it in every scene. So I guess using don’t destroy on load would be better.

As an altrnative, you could also make a prefab out of your UI and simply instantiate it after a level has been loaded.

Regarding what system to use (scenes/prefabs) for changing of levels, that depends alot on the kind of game you are building. If its e.g. a shooter where the levels must be hand built in advance, scenes is probably the way to go. If you have a simple puzzle game like breakout, then building the scene out of prefabs via a level-generator script may be better.

I hope this helps! Good Luck!

use DontDestroyOnLoad for the UI.

As for the levels, I don’t know what game you’re making, but I’d do one of these:

1: Make different scenes for each level
2: Make a script to spawn objects for every level.