Problem with instantiate() and add_child()

Godot Version

4.5

Question

Instantiate() doesn’t work ?

I’ve been using godot for a while and I’ve been doing this little bit of code a lot of times, even in my current project I’ve added this very basic method and it works. But for some reason it doesn’t work here ;

I’m trying to spawn a scene in, using this code:

func _ready():
    var child_scene : PackedScene = preload(res://scene_to_instantiate.tscn)
    var child_instance = child_scene.instantiate()
    add_child(child_instance)
    print(child_instance)

This prints <Object#null> in the console.
Where did I mess up // what should I be looking out for ?

Thanks a lot !!
PS: printing the child_scene gives the PackedScene ID, so it exists

In case someone stumble across that the problem was solved by replacing preload() with load().

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