Periodic function

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

Is there way to create function that would execute with specific period or should be everything that happens periodically happen in _process()?

:bust_in_silhouette: Reply From: timothybrentwood

Use a Timer node to have a function happen every x seconds:

extends Node2D

var my_timer : Timer

func _ready() -> void:
	var optional_parameter = 3
	my_timer =
	my_timer.autostart = true
	my_timer.wait_time = optional_parameter # however many seconds you want
	my_timer.connect("timeout", self, "my_function_to_call", [optional_parameter])
func my_function_to_call(secs):
	prints("This is printed every", secs, "seconds.")