![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | Cakey49 |
When I try to instantiate an object using this code…
extends Node2D
onready var sandScene = load("res://Scenes/Sand.tscn")
onready var sand = sandScene.instance()
func _physics_process(delta):
if Input.is_action_just_pressed("place_object"):
sand.position = Vector2(rand_range(10, 980), rand_range(10, 980))
add_child(sand)
… it comes up with the error:
add_child: Can’t add child ‘Sand’ to ‘Objects’, already has a parent
‘Objects’.
I’m new to using godot and gdscript so I might have a really obvious mistake but all the videos I have watched haven’t helped.
Try
if Input.is_action_just_pressed("place_object"):
var s = sandScene.instance()
s.position = Vector2(rand_range(10, 980), rand_range(10, 980))
add_child(s)
ramazan | 2022-08-07 20:43