How does add_child() work?

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

So I’m trying to make an endless runner and I took a code from the internet for the endless generation.
So here is the code:

extends Node2D
export (Array, PackedScene) var scenes

func _ready():

func _physics_process(delta):

func add_wall():
	for scene in scenes:
		var object = load("res://Scenes/Objects1.tscn")
		var objectinstance = object.instance()
		objectinstance.position = Vector2(80, -200)

If I run the code nothing happens, no error no warning just nothing. I tried different tutorials too, but there was no difference at the result. Whats wrong with the code?

:bust_in_silhouette: Reply From: Macryc

you should be adding the instance of the loaded scene, not the scene itself.
try this:


Thanks for your answer

Criepstar | 2020-09-07 16:59