Timer reference, mob spawner

Godot Version

4.2.2

Question

I cant seem to reference the timer, every attempt says its null

I want to make a spawner, that emits a signal every timeout and send waves left and a reference to the object created.
when the player pressed an action key it places a spawner creating a new object of spawner class
The main script will check if waves left is 0, and then call queue_free

problem is i cant seem to get the timer going other than the 1st instance, because im using the checkbox on the left to start autotimer. Subsequent placements do not start timer

If the timer is part of your spawner, ie a node in the spawner scene, you can use autostart setting to make it start the moment it enters the tree.

Then on the timeout function you can just restart the timer.

func _on_Timer_timeout():
    # Restart the timer
    $Timer.start()

Usually when a node reference I know should be valid, but has only just been added to the tree, is returning as null, it is usually because I have tried to access it too soon. I recently discovered call_deferred, which I use a lot now.

Perhaps starting the timer with a call_deferred might help here too.

func _ready():
    call_deferred("_start_timer")

func _start_timer():
        $Timer.start()

Hope that helps in some way, although I am also a beginner so I might be on completely the wrong track here. If I am, apologies in advance :slight_smile:

Paul.

Tried this, still getting it as Null instance

In your ready function do this:

print("var timer is: ", timer)

Is it still null? If so there is something wrong here I would guess:

@onready var timer = $Timer

Is your timer node actually called Timer and a direct child?