0 votes
print(pickable)
pickable.get_parent().remove_child(pickable)
print(pickable)
add_child(pickable)

pickable is the child l want to change his parent. But after call the remove_child, pickable become null. Log shows like:

    pickaxe:<RigidBody2D#27078427832>
    <null>

can anyone help me, thanks

Godot version 4.0 beta1
in Engine by (21 points)

What happens if you re-add it? It might be because it's briefly an orphan.

1 Answer

+1 vote

You want to use move_child not remove_child.

Documentation is here, https://docs.godotengine.org/en/stable/classes/class_node.html?highlight=move_child#methods

by (3,321 points)

thanks, but not help. The script node and the pickable node have same parent, and l want the pickable to become current script node's child.

And the main question is this: why remove_child() will make pickable node null? So strange

The remove node will set the owner of the removed Node (or its descendants) to be null, if that owner is no longer a parent or ancestor.

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.