Error: "Invalid call. Nonexistent function 'instance' in base 'Nil'."

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By EdgyBlock

Hi, i’m a complete beginner to godot so sorry if my code is unreadable trash. Here it is:


extends Sprite
export (PackedScene) var Pipe
onready var new_pipe = Pipe.instance()

func spawn_pipe():
new_pipe.position = Vector2(-30.941, 4.235)
add_child(new_pipe)
print(“Duplicated”)


I’m sorry i cant get the code sample thing to work ):

For context, i’m making a flappy bird clone and i need the pipes that you go over to spawn and spawn and spawn. The spawn pipe function is hooked up to a timer and it gives the error above.

1 Like
:bust_in_silhouette: Reply From: kidscancode

The error is telling you that the variable Pipe has no value (“Nil”). This is because you’ve written code to have it assigned in the Inspector, but it seems you haven’t assigned it a value. Go to the inspector and drop the scene file in there.

Also, the way you’ve written it, you’re only making one instance ever for the whole game. This line:

var new_pipe = Pipe.instance()

should appear in your spawn() function if you want to be able to make a new pipe every time you call it.