How to use a Script to change Nodes, while a scene is running?

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

Im trying to get my head around how to use the “Methods” of Nodes like get_tree().get_root() or remove_and_skip or any of them.

To make my problem more comprehensible here some short code where i try to delete a ColorRect and a Label out of the scene.
The SceneTree: Node2d → ColorRect → Label

extends Node2D

onready var a = $ColorRect
onready var s = $Label

func _ready():


This is probably completely wrong. I tried to understand the Docs but i got confused, maybe i miss something? help me correct it pretty please and thank you for your time <3

:bust_in_silhouette: Reply From: volzhs

if you want to remove a node and its children node from scene,


if you want to remove a node but keep its children node from scene,


you don’t need to get_tree().get_root()...