Godot Version
v4.1.2.stable.official [399c9dc39]
Question
I’m new to Godot, and I can’t figure out how to copy a node and change it’s parent. I have this code, which isn’t producing any errors, but when I run it nothing physically changes in the scene
extends Node2D
var canPlaceNew = true
var ButtonLayer
var CopyImage
func _input(event):
if event.is_action_pressed("NewImage") and canPlaceNew == true:
var CopyImage = get_tree().get_first_node_in_group("CopyImage")
var ButtonLayer = get_tree().get_first_node_in_group("ButtonLayer")
print("I Placed A New Image Look At Me Go")
var DirtyPlagarist = CopyImage.duplicate(true)
DirtyPlagarist.name = "SuchAPlagarist"
var new_parent = ButtonLayer
get_parent().remove_child(DirtyPlagarist)
new_parent.add_child(DirtyPlagarist)
DirtyPlagarist.position = Vector2(374, 423)
CopyImage is the node I am copying and ButtonLayer is the UI layer. I am using groups to get the nodes because the script is an autoload and I can’t find another way to get the nodes. I can provide more information if this isn’t enough. If the solution to this problem is obvious, please write your answer in comic sans so that I know I’m an idiot. Thank you.