Hi folks! I'm trying to understand the difference between all of the methods I've come across of adding a new node to the root of a scene.
The node is being added from an arbitrary node in the scene
Imagine a new 3D scene (Spatial as root node), and one child node with a script that adds more nodes
extends Node
func _ready():
var new_node = CSGBox.new()
var root
# The Godot Docs FPS Tutorial Method
# https://docs.godotengine.org/en/stable/tutorials/3d/fps_tutorial/part_two.html#creating-the-first-weapon
root = get_tree().root.get_children()[0] # root is Spatial Node
# Viewport Method
# https://docs.godotengine.org/en/3.3/getting_started/step_by_step/scene_tree.html
root = get_tree().get_root() # root is Viewport
# The HeartBeast Method
# https://youtu.be/1mI04gPhd3E?t=1518
root = get_tree().current_scene # root is Spatial Node
print(root)
root.call_deferred("add_child", new_node)
Both of those methods work. What's the difference between adding a child to the root viewport, vs adding a child to the root node (is that even a thing?)
Are there other ways to do this?