"instantiate" is a Nonexistent Function?

Godot Version

Godot 4.2

Question

I am making a game in Godot that requires enemies to spawn and run after you. i was following this tutoriall, and am stuck on the last bit.

The code calls for one of the lines to be:var e = enemy.instantiate(). And after i put that in:

func spawn_enemies():
for x in range(9):
for y in range(3):
var e = Enemy.instantiate()
var pos = Vector2(x * (16 + 8) + 24, 16 * 4 + y * 16)
add_child(e)
e.start(pos)
e.died.connect(_on_Enemy_died)

func _on_Enemy_died(value):
score += value

Why is it saying that? What is wrong with this line “var e = Enemy.instantiate()” in my code?

Don’t mix Enemy and enemy. Use the lowercase option, just like the tutorial says.

2 Likes

Totally an issue with capitalisation. Enemy could/should be a class type where as enemy would be a var you set.

var enemy = preload(“yourenemyscene”)

Then enemy.instantiate should work.

Hopefully you get it sorted :slight_smile: