get_tree().paused game does not work for two diferend nodes?

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

Hi, I making a racing game project and i have a problem with get_tree().paused....
I am using it first time for the “lights”, when the race is started. After the lights out, get_tree().paused = false then i can pressed escape button for “pause menu” in the race. But it is not pause game (its just instance pause menu - witch have in script if is _ready(): get_tree().paused = true, but it is not hapend).
But when i delete lights from the files the “paused menu” works, but there is nothing betwen them, just same parent call “main”.
Scene tree after instancing: main/racing gui/lights and main/paused menu/
Both of them have Paused mod change to proces, other nodes in the tree have Inherit. Does somebody know where is a problem? Can it be a bug of godot?

Are you sure your pause menu is pausing the scene tree AFTER the lights unpause it?

Zylann | 2018-09-06 12:43

yes, I am sure, because player can not move until the lights are out…
here is the part of lights script (light is var, if Lights_timer_timeout, light +=1 and game_run is var in main scene after that start working escape button for pause menu):

func _process(delta):
if light >= 6:
	$Lights_Timer.stop()
	get_tree().paused = false
	get_parent().get_parent().game_run = true
	if transparency != 0:
		transparency -= 0.02
	else:
		queue_free()
$CanvasLayer/Light_Sprite.modulate = Color(1,1,1,transparency)

popon2 | 2018-09-06 12:58

:bust_in_silhouette: Reply From: popon2

I do not know why, but this works (i change script in pause menu):

extends Control

var pause = false

func _ready():
	pause = true
	
func _process(delta):
	if pause == true:
		get_tree().paused = true
	else:
		get_tree().paused = false
	
func _on_RESUME_pressed():
	pause = false
	queue_free()
	
func _on_QUIT_pressed():
	get_tree().quit()

you could use a setget function to handle the pausing

var paused: = false setget set_paused
var scene_tree = get_tree()

func _unhandled_input(_event):
	if Input.is_action_just_pressed("pause"):
		self.paused = not paused
        scene_tree.set_input_as_handled()

func set_paused(value: bool):
	paused = value
	scene_tree.paused = value

Surtarso | 2021-02-18 17:12