Best way to activate a pause menu.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By DriNeo
:warning: Old Version Published before Godot 3 was released.

Hi, I’m currently implementing a pause menu to pop during game execution.
I have two easy solutions.
-Instancing a scene who contains the pause panel.
-using show().

show() and hide() activate or deactivate the controls and it’s probably faster because the nodes of the pause menu stays available into memory. But I could forgot something.
What is your opinion ?

You can instance the scene and keep it in a variable (on the current scene or a global), then add it to the tree when pausing the rest and remove from the tree when closing the pause window, keeping the instance.

eons | 2016-12-12 19:06

Your solution seems cleaner to me. Using remove_child() and add_child() works fine.

My PC is too fast to evaluate the lag when I hit pause button. I will see this when I will export the game to my old Android phone.
Thank you, you can change your comment to an answer if you want.
Sorry if my english is not very good :wink:

DriNeo | 2016-12-12 20:22

:bust_in_silhouette: Reply From: rgrams

show() and hide() (or set_hidden()) have always worked fine for me. It shouldn’t have any performance impact sitting there hidden. It seems silly to possibly delete and recreate it multiple times in one playthrough.

If my old phone lags when I hit the pause button I will use your solution.
Thanks for the answer.

DriNeo | 2016-12-12 20:24

:bust_in_silhouette: Reply From: eons

Another option is to get the instance in a variable (on the current scene or a global one) and just add and remove from the tree when pausing/unpausing.

That is not a bigger advantage over other methods but you can be sure nothing is processed when not paused since the pause scene won’t be on the tree.

Keep in mind that re-entering the tree triggers again _ready and _enter_tree, keeping a variable to remember that is not the first time it enters the tree may be needed.
This could be used for altering the pause menu according to the game state too.