preload operator (SCRIPT) and node addition (GUI)

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

Hi there,

Please, let me know if I am wrong: assuming all resources below exist and they define only the their inheritage as suggested by their name:

extends Node2D

onready var Map =  preload("res://TileMap.gd").new()
onready var Player = preload("res://KinematicBody2D.gd").new()

is it the same (or equivalent) as adding a node via GUI to the node which the script above is attached to?

:bust_in_silhouette: Reply From: Lopy

No. You create two Nodes, but without adding them to the tree. You need to add a couple of add_child() in your _ready().