0 votes

In 2D: How to switch the position of a child from one parent to the other while maintaining the same global position?

Provided each parent has a different origin position.

Godot version 3.2.3
in Engine by (15 points)

1 Answer

+1 vote
Best answer
  1. Save the child's global position
    var location = child.rect_global_position

  2. Move the child in the tree
    old_parent_node.remove_child(child) new_parent_node.add_child(child)

  3. Reset the position
    child.rect_global_position = location

by (4,304 points)
selected by
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 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 webmaster@godotengine.org with your username.