How do I wait a few seconds in my init method?

Hello, I’m very new to Godot and I’m wondering how I would be able to wait a few seconds and then have something happen inside of the _init method?

My current code

extends Node
class_name ObjectAnimation

var jsonString = ""
var animationData = {}
var frameTime = 0
var paused = false

func _init(_jsonString : String):
   self.jsonString = _jsonString
   self.animationData = JSON.parse_string(self.jsonString)

You probably do not want a _init with required parameters on a Node class, this makes it very difficult to instantiate, and you cannot easily wait with it. Try using _ready instead, when creating the object you will have to alter jsonString before adding it as a child

func _ready() -> void:
   self.animationData = JSON.parse_string(self.jsonString)
   await get_tree().create_timer(0.5).timeout # delays half a second
1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.