How would I optimize menus?

Hello all,

I am wondering what the best way to do multiple menus is. Currently I am just making buttons that go to a whole new scene when clicked. I feel like there is a better way to do menus. Here is an example:

Play button is pressed, menu with level selection screen shows up.

Thank you!

It partially depends on what UI library are you using. The main inefficiency with using scenes would unloading/loading resources, if it is signficant enough to warrant optimization, then you could consider making some objects persistent using DontDestroyOnLoad. If you want to do it all in a single scene, then you can make your own UI menu screen manager. It would just be a simple finite state machine.

Would you say that loading a whole new scene uses a lot of unnecessary resources?

I’d say the biggest factor is loading time, if it takes 500ms to switch menus then that is a problem, if it is pretty snappy I wouldn’t worry about it too much.

The fastest way would be to have just one scene with all your menus and buttons (layering them helps with organization). Then make the buttons that move between menus also enable and disable the appropriate elements. For example, pressing “Options” on the main menu would disable all the main menu buttons and graphics and then enable the options buttons and graphics. That way everything will be very quick. Also, having everything in one scene means you could do things like physically move the menus to create slick transition effects.

I use Above and beyond’s easy GUI! It’s fast and easy.

Loading a scene is a bit over the top.

You could try a game object for each “screen”, then an animation on this which “rolls out” the menu with an animation event that then triggers the next menus “roll in” animation.

Of course animations are optional you could just disable/enable, or have a fade in/out script.

I’m using a mixed approach. For level select, I actually have a full 3D scene. For the more simple stuff like, getting the player name, showing a recap of the last level played, etc. I’m using prefabs with code attached and instantiate them as needed; destroying them when done. Similar to what JohnnyA is suggesting.

I’m reluctant to invest the time it takes to learn an add-on solution with a new native one coming soon.

I do like the gameobject approach in that its a fairly easy way to do things like pop up windows and such that are common to multiple scenes. I control them all from a static game manager class allowing me to do things like:

GameManger.ShowWarning("Warning", "A profile with this name already exists");

That’s a really basic example, but you can do whatever you’d like.