Pause button and Resume button

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Nick888

I have a main World scene that i play my game. In this scene i have on the top a pause touch screen button.

Also i have and a Pause scene with two buttons: A Resume touch screen button and a Quit touch screen button. The Pause scene is a node scene in World scene (instance a scene as a node).

From the Pause button i send a signal to the World node script:

func _on_Pause_pressed():


When i press the pause button during the gaming the game stops and i can see the Pause scene with the Resume and the Quit Button. When i press the Quit button the game close normally.

func _on_Quit_pressed():


But when i press the Resume button the game does not continue but i just see a grey scene:

func _on_Resume_pressed():

get_tree().paused= not get_tree().paused
visible= not visible

Any idea please?

Thank you.

:bust_in_silhouette: Reply From: Dlean Jeans

get_tree().change_scene() changes the main scene to a new one and frees the current one, in this case, to the PauseScene and frees the World scene, which is why you see nothing after resume.

What you need is to show the PauseScene, not change to it:

func on_Pause_pressed():
    get_tree().paused = true

Thank you about your reply.

I wrote your code in func on_Pause_pressed(), but the game stops and i get the following error:

Invalid set index ‘pause’ (on base: ‘SceneTree’) with value of type ‘bool’.

Nick888 | 2019-07-02 16:03

I wrote this:

func _on_Pause_pressed():

get_tree().paused=not get_tree().paused

I can see the Pause Scene now but the Resume and Quit buttons don’t responding…

Nick888 | 2019-07-02 16:19

i suppose that the Resume and Quit button don’t responting because the Pause button froze all the World scene tree.

Nick888 | 2019-07-02 16:29

I corrected something in your code:

func on_Pause_pressed():

get_tree().paused = true

Now i can see the PauseScene but still the Resume and Quit buttons don’t responding…

Nick888 | 2019-07-02 16:33

My bad on the paused property.
Just set the Pause Scene’s Pause Mode to Process.
There’s an official docs on Pausing games.

Dlean Jeans | 2019-07-02 17:32

Thank you so much!
It is working perfectly now!

Nick888 | 2019-07-02 17:54