0 votes

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

in Engine by (15 points)

1 Answer

+1 vote
Best answer

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 = Timer.new()
    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])
    self.add_child(my_timer)

func my_function_to_call(secs):
    prints("This is printed every", secs, "seconds.")
by (3,888 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.