+1 vote

I am trying to change the parent of my current node.

in Engine by (350 points)

1 Answer

+4 votes
Best answer

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")

Reference the parent before you unparent:

var new_parent = get_parent().get_parent()
by (343 points)
selected by

somehow I get 'addchild' in base 'null instance' after removechild
func _process(delta): if target and get_parent() != get_node(target): var new_parent = get_node(target) get_parent().remove_child(self) new_parent.add_child(self)

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.