Nonexistent function instance in base area2d (bullet.gd)

Im trying to make a top down shooter and when I shoot it blows up and displays this:

extends Node2D

var bullet = load(“res://bullet.tscn”).instance()

Called when the node enters the scene tree for the first time.

func _ready():
pass # Replace with function body.

Called every frame. ‘delta’ is the elapsed time since the previous frame.

func _process(delta):
look_at(get_global_mouse_position())
if Input.is_action_just_pressed(“click”):
var billet = bullet.instance()
bullet.position = position
get_parent().add_child(billet)
This is the bullet script:
extends Area2D

var speed = 600

Called when the node enters the scene tree for the first time.

func _ready():
pass # Replace with function body.

Called every frame. ‘delta’ is the elapsed time since the previous frame.

func _physics_process(delta):
position.y -= speed * delta
I am using godot 3

Try adding child before setting position.

Also, why are you instancing an instance? You can remove . instance () here, since you’re creating another instance here

Removing instance there actually worked thanks

wait now it’s givign me the error that i cant add a child to the node as it already has a parent

did you indented the get_parent().add_child(billet)

get_tree().get_root().add_child(billet)

get_root()??? Why? I feel like this is unnecessary

He is experiencing an issue with adding a child to a node since it already has a parent, so my solution was to place it in the main game scene through “get_tree().get_root().add_child(billet)”

1 Like

ohh i get it now, thanks for explaining :]