Topic was automatically imported from the old Question2Answer platform.
Asked By
i dont like
i need my player to become parented to other objects sometimes, and im trying to do this in a state of the character controller in the physics process
this is what i have for the state:
if current_state == State.cockpit:
get_parent().remove_child(self)
get_node("/the_game/Spaceship").add_child(self)
when i try to activate the state, it says that the node i am trying to get is null. both the player and the part id like it to be parented to are only children of the root part
what am i doing wrong and is there a better way to do this
Maybe you should tryget_tree().get_root().get_node("the_game/Spaceship"), assuming “the_game” is your base scene node,
instead of get_node("/the_game/Spaceship"), as I don’t think that Godot NodePaths which start with “/” mean “relative to root node”.
I don’t think the problem is related to your parenting at all. The node path you’ve noted just isn’t valid. Really, you probably want this: