0 votes

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 onPause_pressed():

#

get_tree().set_pause(true)
get_tree().change_scene("res://PauseSceen.tscn")
pass

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 onQuit_pressed():

get_tree().quit()
pass 

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
pass

Any idea please?

Thank you.

in Engine by (219 points)

1 Answer

+1 vote
Best answer

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():
    $PauseScene.show()
    get_tree().paused = true
by (4,155 points)
selected by

Thank you about your reply.

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

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

I wrote this:

func onPause_pressed():

#

get_tree().paused=not get_tree().paused
$PauseScene.show()

I can see the Pause Scene now but the Resume and Quit buttons don't responding...

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

I corrected something in your code:

func onPausepressed():

#

$PauseScene.show()
get_tree().paused = true

Now i can see the PauseScene but still the Resume and Quit buttons don't responding...

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

Thank you so much!
It is working perfectly now!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.