0 votes

Hello everyone. I'm following this tutorial to make arrows to my game. However, when I try to fire the bow the game crashes and the following error keeps pops up:

"Invalid call. Nonexistent function 'Instance' in base 'Nil'."

The guy in the video is attaching his script to KinematicBody2D Player, but I want the bow my character uses to move with the mouse, so I'm assigning this script to the bow.

Any ideas on how to fix this? I am new to programming in general, so you'd help me a lot. Thanks in advance.

This is my code:

extends Node2D

onready var bow_end = $BowEnd
onready var bow_cooldown = $Bowcooldown

export (PackedScene) var arrow

func _process(_delta): look_at(get_global_mouse_position())

func _unhandled_input(event: InputEvent) -> void: if Input.is_action_just_pressed("ui_attack") and is_visible_in_tree(): shoot()

func shoot(): var arrow_instance = arrow.instance() add_child(arrow_instance) arrow_instance.global_position = bow_end.global.position

If any more information is needed, I'll be happy to provide.

Godot version v3.5.1
in Engine by (35 points)

Which line is giving you the error?

1 Answer

+1 vote
Best answer

It looks like you haven't set "arrow". Click on this scene in the editor, and on the right-hand side should be an "arrow" setting, in which you'll need to select your arrow node.

by (1,053 points)
selected by

That was indeed the issue, thank you so much. However, now the next line is the problem. The error changed to "Invalid get index 'global' (on base:'Position2D')." Any ideas?

bowend.global.position -> bowend.global_position

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.