How to add instances using function from another script?

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

var spawner = load("*path to*").new()

func _physics_process(delta):
var load_type = preload(“thing.tscn”)

var instance = load_type.instance()
fun spawn():
move_child(instance, 3)

But the problem is nothing changes.

I typed the line below add_child print(instance.get_path())

Output is:

Cannot get path of node as it is not in a scene tree.

:bust_in_silhouette: Reply From: klaas

When spawner is not in the scene tree the added child will mit appear in the scene.