Timers break when I load a scene

Godot Version

Godot 4.2

Question

How do I fix a timer breaking whenever I load a scene?
I use timers on the title screen of my game for various purposes (allowing time for a confirmation sound to play, and showing an error message), and they work exactly as I expect when I directly load into the title screen scene of my game. However, as soon as I return to the title screen, the timers break, and none of the options work as I expect. I’ve tried both creating the timers in code and using nodes and the same exact thing happens. I’ll attach the code for my title screen if anybody can provide help or a better solution.

Note: The uiOption variable is leftover from me using nodes and a single timeout function.

extends Node3D
var uiOption = 0

func _ready():
	$interface/ExtrasErr.hide()
	if Global.version == 3 or Global.version == 4:
		pass
	else:
		$music.play()

func _process(delta):
	pass

func _on_play_pressed():
	$uiYes.play()
	uiOption = 1
	await get_tree().create_timer(0.5).timeout
	get_tree().change_scene_to_file("res://scenes/testing_stage.tscn")

func _on_quit_pressed():
	$uiYes.play()
	uiOption = 2
	await get_tree().create_timer(0.5).timeout
	get_tree().quit()

func _on_extras_pressed():
	$uiYes.play()
	if Global.gemsCollected == 11:
		uiOption = 3
		await get_tree().create_timer(0.5).timeout
	else:
		$interface/ExtrasErr.show()
		await get_tree().create_timer(5).timeout
		$interface/ExtrasErr.hide()

func _on_options_pressed():
	$uiYes.play()

Please provide the exact issue you are encountering (error message, expected behavior)
Also can you please give more details into your transition system ? how do you “return to the title screen” ? what is it composed of ?

Are you putting the game on pause by any chance ?

1 Like

This did make me realize the issue, in the pause menu I set the engine time scale to zero and never set it back to 1. Thank you!

remember to flag your post as solution so the topic appears solved :innocent:

My solution is to have one Main Scene you will manage change levels in this scene, timers and all logic between levels

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.