![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
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 Stem.gd
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 = Timer.new()
timer.set_wait_time(2)
timer.connect("timeout",self,"_on_timer_timeout")
timer.set_one_shot(true)
#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()
leaf.set_position(Vector2(0,-35))
add_child(leaf)
func grow_stem():
var stem_resource = self.instance()
stem.set_position(Vector2(0,-35))
add_child(stem)
func _on_timer_timeout():
print("GrowLeaves")
grow_leaves()
print("GrowStem")
grow_stem()
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