#Problems with making clones (instantiate())

8 messages · Page 1 of 1 (latest)

fresh willow
#

the pipe doesn't spawn

fresh willow
#

code update:
extends Area2D
var repeater = preload("res://pipe.tscn")
func _ready() -> void:
position.x = 525
position.y = randf_range(400,-300)
func _process(delta: float) -> void:
position.x -= 25
func _on_area_entered(area: Area2D) -> void:
if area.is_in_group("spawner"):
var spoink = repeater.instantiate()
add_child(spoink)
queue_free()

#

and it doesn't work

#

🥶

kindred badge
#

What do you want to add the instantiated object to? As a child of what game object?

Currently it looks like you are instantiating a thing, adding it as a child of this area, then you free this area and all of its children (including the newly instantiated object).

fresh willow
#

it is a "flappy bird game" with a zone at the end of the camera, if the pipe touches it clones itself

kindred badge
#

This may need be the "final" solution, but try instead doing get_tree().root.add_child(spoink)

Not sure that the queue_free() is necessary.. Not sure your full setup

fresh willow
#

OMG this worked