![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | SDGN16 |
I added code to the home screen that adds an object every 3 seconds, but I’m getting errors.
add_child: Can’t add child ‘cube1’ to ‘world’, already has a parent ‘world’.
add_child: Can’t add child ‘cube2’ to ‘world’, already has a parent ‘world’.
add_child: Can’t add child ‘cube3’ to ‘world’, already has a parent ‘world’.
world.gd
extends Spatial
var obj1 = load("res://cube1.tscn")
var obj2 = load("res://cube2.tscn")
var obj3 = load("res://cube3.tscn")
var ins1 = obj1.instance()
var ins2 = obj2.instance()
var ins3 = obj3.instance()
var rng = RandomNumberGenerator.new()
func f():
rng.randomize()
var ran = rng.randi_range(1,3)
if ran == 1:
self.add_child(ins1)
if ran == 2:
self.add_child(ins2)
if ran == 3:
self.add_child(ins3)
else:
pass
func _on_tm_timeout():
f()
the code inside the scenes added to the screen (cube1.gd,cube2.gd,cube3.gd)
extends StaticBody
var v = Vector3(0,1,-50)
func _process(_delta):
if v.z > 0:
self.queue_free()
else:
v.z += 0.1
self.set_translation(v)
I’m trying to make an endless simple running game.