timer not working in script without scene

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

I created a script, blink .gd, without a scene, the essence of which is to teleport an object to the mouse


onready var _blink = preload("res://src/characters/skills/blink/blink.gd").new()
func blink():


var _timer    : Timer = null
var _cooldown : bool  = false

func _init():
	_timer = Timer.new()
	_timer.connect("timeout", self, "_reload")
func skill(_target: KinematicBody2D) -> void:
	if !(_cooldown):
		_cooldown = true

func _reload():
	_cooldown = false

and it doesn’t work. I checked _timer.is_connected and it returns true.
I did something similar in scripts attached to scenes and the timer worked.

I added to player.gd code add_child(_blink), and timer work, but the script no longer teleported the player.
Sorry for any mistakes, English is not my native language.

:bust_in_silhouette: Reply From: Feanor

Okay, I found the answer.Maybe someone will need it


really help me. I suspect this is because the timer doesn’t work without an active scene attached.

I have found that too. For timers to work, you need it to be part of the scene tree.

godot_dev_ | 2022-09-21 13:48