0 votes

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()
    #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?

Godot version 3.2.3
in Engine by (12 points)

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

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

1 Answer

+1 vote

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

by (881 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.