Reparenting a node

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By hidemat

So I’m making a tetris like game. I setup my scene like so:

--Ysort # meant to contain the pieces that the cart deposits
--Cart # transports the piece from top to bottom
  --Piece # the piece is just a block

So I want it so that when the cart reaches the bottom of the grid the piece it is transporting gets reparented to the Ysort. I know how to setup the movement, collisions, signals, and get them working. I just don’t know how to move the Piece from the Cart to the Ysort. How do I do this?

:bust_in_silhouette: Reply From: hidemat

Oh I figured it out. When the cart hits the bottom I had to:

  1. Store the piece in a variable.
  2. call the remove_child() fuction on the cart
  3. the add_child() on the Ysort

var piece = cart.get_node("piece")

Word to the wise: Let the parent re-parent nodes