0 votes

oMain------------------------- o GemControl
-gem_container------------- Gem


  extends Node2D
        var lastpos
        var positions=[]
        var screenSize
        onready var gems=get_node("Gem")

        func _ready():

        func _on_gem_collided():

        func _get_gems_position(pos):
        func spawn_gems(num):
            for i in range(num):

                var g=gems.instance() #--------Problem-----


func _ready():
    var g=gem.instance()

There is an error says Nonexistent function 'instance' in base 'Sprite'. Line ....var g=gems.instance().... creates a problem.
I am trying to understand why i cant make instance of sprite(GEM) from its parent Gem_control. I am new to godot. Thanks in advance.

in Engine by (35 points)

1 Answer

+1 vote
Best answer

Because gems is a node. You can't instance a node, you can only instance scenes, which is saved on disk.
You may wanna duplicate the node instead:

var g = gems.duplicate()
by (4,221 points)
selected by

Thank you.You are right.I confused since every scene is a node. I didnt think it was different. gems.duplicate() works and if someone want to maintain node properties there are flags to add ( gems.duplicate(15))

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 Frequently asked questions and 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 [email protected] with your username.