Add_child before changing a Node variable

Hello,I just want to know if it is possible change a variable of a node after i added it of the scene without changing the scene.A bit like this :

extends Node2D
var obj :Node2D =Node2D.new()
add_child(obj)
obj = Area2D.new()#I don't wan't to change the first child of the node 
add_child(obj)

So I can create multiple nodes with different property

Yes, this works because a variable of Object type only stores a reference to the object, not an actual value. You could have just tested this yourself though…

1 Like