When you unparent a node, the return value of get_parent()
will be null. So you cannot use get_parent()
when it has no parent.
var new_parent = get_node("/root/AnotherParent")
get_parent().remove_child(self)
new_parent.add_child(self)
Reference the parent before you unparent:
var new_parent = get_parent().get_parent()
get_parent().remove_child(self)
new_parent.add_child(self)