My Timer Isn't Sending Timeout Signal

Godot Version

godot 4


Please go easy on me, this is my first attempt at Godot. I’m trying to write a code that will be a general “respawn platform” script for all crumbling platforms in my game, but the timer I’m using for the respawn isn’t working. I’ve checked that it reaches up to the line ‘await respawn_timer.timeout’ by using prints, and I checked that the timer isn’t stopped or paused after the start() function using if statements. The problem seems to be that the respawn timer’s timeout signal either isn’t being sent or isn’t being received. I have a similar function for when the platforms are actually crumbling, and that timer works just fine.

I really don’t understand what the problem here is, and I’ve had to remake the node and the scenes it was in because a timer node corrupted it. I know that because I opened the scene file in notepad and after deleting the timer node it wasn’t saying it was corrupted anymore. Please let me know what I’m doing wrong.

@export var crumble_time : float = .5
@export var respawn_time : float = 2.0
@onready var crumble_timer : Timer = $crumbletimer
@onready var respawn_timer : Timer = $respawntimer
@onready var loaded_instance : Resource

func _ready():
	crumble_timer.wait_time = crumble_time
	respawn_timer.wait_time = respawn_time

func respawn_platform(old_position,old_scale):
	var new_object = loaded_instance.instantiate()
	new_object.position = old_position
	new_object.scale = old_scale
    #it reaches until this point with no issues
    await respawn_timer.timeout

I would double check the properties of the timer in question, and also make sure that the nodepath you are specifying for the $respawntimer is correct.

Two things I always tend to forget at:

  1. Oneshot
  2. Loop

Properties on the timer, so double check those.

You can also see if the timer is started or decrementing properly.

I would also definitely make use of breakpoints in the editor to see if there’s anything you can trace there!

Thank you for the advice, but I’m starting to think it’s a problem with Godot. My crumbling platform scene, as well as all the scenes it’s in, just got corrupted again. I’m at a loss now.

Are you using any custom plugins or anything? I would be confused as to why your scene would unexpected be corrupted

Did you put a print after the await statement to see if it got there?
You don’t say what makes you suspect that the timeout signal isn’t firing.
Is it because the new_object isn’t added?
If so it might not have anything to do with the timer.
Try putting print(new_object) after the await line.

After some testing I found out what was corrupting the scene. The problem hasn’t been the timers at all. Assigning an inherited variable called respawn_backup, which was going to be a preloaded resource of each unique platform, is what’s causing the scene to get corrupted. I’m not familiar enough with the file path system to now why, but I’m trying to fix it by creating a parent node for all respawning platforms that’ll have a dictionary of each unique platform and its respawn_backup. Here’s the bit of code that was corrupting the scene:

func _ready():
	respawn_backup = preload("res://objects/obstacles/platforms/crumbling/rect/rect_crumbler.tscn")

Now, I’m just going to manually create a dictionary of all the unique platforms with the names of the nodes being the keys. The ready function connects the relevant preload to each child node as well as the respawn function.

var crumbling_platforms : Dictionary = {
	'RectCrumbler': preload("res://objects/obstacles/platforms/crumbling/rect/RectCrumbler.tscn")
var respawn_backup : Resource
var respawn_timer : Timer

func _ready():
	for child in get_children():
		if(child is Crumbler and in crumbling_platforms.keys()):
			var current = crumbling_platforms[]
			#assigning the relevant variables
			child.respawn_backup = current

After doing ALL of this, I’m realizing I got distracted from figuring out the timer thing, so that’s next.

I just tried printing new_object before and after awaiting the timeout, and only the first printed. It looks like it is the timer that’s causing the problem.