Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it more efficient to change scenes in Unity or to have different ui screens?

I've been working on a really simple game for iOS that has just three scenes; the start scene, game scene, and game over scene. I was running the game and analyzing performance with the profiler and I noticed that when I changed scenes, which utilized the "SceneManager.LoadLevelAsync()" function, the CPU usage was around 90%. This is only for less than a second of course, and then the CPU usage drops again and I get around 70-80 fps, but this got me wondering if it would be more efficient for a simple game like this for me to simply have several UI "screens" (basically just a group of objects that I can activate and inactivate), which is what I did with my pause screen (it is just an overlay).

Of course this could have difficulties of its own, like I would have to restart the game on the same scene but it might help me with my problem of running the mute function I've built on my music manager, which is instantiated in the start scene, from a button that is on my game scene, and I wouldn't have to use the "DontDestroyOnLoad()" function on the music manager or my score manager (which stores the score to be displayed on the game over scene). But would it be inefficient to have so many inactivated objects, or is Unity pretty good at managing things like that?

like image 778
Andrew T Avatar asked Jan 05 '23 04:01

Andrew T


1 Answers

In my personal opinon, menu system should be in one scene.

Having different scenes for every menu screen will cause overhead. Even it is for few micro seconds it will affect user experience when navigating between menus frequently. This is because of loading and destroying of each UI gameObject in scene.

While menu system based in one scene requires only activating and deactivating of gameobjects instead of instantiating and destroying.

You can have one root object for menu and assign it a canvas component and then you can add different panels for each screen and assign them canvas groups to toggle them on and off smoothly.

Here is a good tutorial for creating menu system: https://www.youtube.com/watch?v=DNqTUwnpLvI

Hope this helps.

like image 181
Umair M Avatar answered Jan 13 '23 15:01

Umair M