How to clone a Node and place it in another Node (by using code)?

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

SceneTree:

┖╴Stage1
  ┠╴TileMap
  ┖╴HUD
    ┖╴MiniMap

I need to clone TileMap and place it into MiniMap scene tree

:bust_in_silhouette: Reply From: sash-rc

Literally you need

# Stage1 scope
$HUD/MiniMap.add_child( $TileMap.duplicate() ) 

However, for minimaps they often use separate Viewport + Camera, or just a Texture (pre-rendered as asset, or automatically assembled).

This one wont clone the script and variables though, if you need that though just tell me.

Merlin1846 | 2021-07-29 20:38