How to make a scene have a child of itself

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

I can make another scene a child of any scene. But when I try to make a scene a child of itself I get this error: Parser Error: Can’t preload resource at path: res://Stem.tscn at the line var stem_resource = preload(“res://Stem.tscn”) in

Here is my full code.

extends Area2D

# Declare member variables here. Examples:
# var a = 2
# var b = "text"
var coords = Vector2.ZERO
var timer = null
#var basil_resource = preload("res://Basil.tscn")
onready var global = get_node("/root/Global")
var leaf_resource = preload("res://Leaf.tscn")
var stem_resource = preload("res://Stem.tscn")
# Called when the node enters the scene tree for the first time.
func _ready():
	timer =
	#timeout is what says in docs, in signals
	#self is who respond to the callback
	#_on_timer_timeout is the callback, can have any name
	add_child(timer) #to process
	timer.start() #to start

func grow_leaves():
	var leaf = leaf_resource.instance()
func grow_stem():
	var stem_resource = self.instance()

func _on_timer_timeout():

Why does this error happen? Is there another way to make Stem grow another stem?

Could it be you are getting infinite recursion loading a scene into itself?

wyattb | 2021-05-29 17:27

I’d say the issue here is the preload line
As that is supposed to happen once (when the engine starts)
Change to load and see what happens

Wakatta | 2021-06-11 23:39

:bust_in_silhouette: Reply From: Help me please

You can’t intanciate the same scene in that particular scene but you can duplicate the scene and then try to instance the duplicated scene in your scene