Can't instantiate a child node more than once at the same time

Godot Version

v4.2.2.stable.official [15073afe3]

Question

extends Node2D

@onready var gangster = preload("res://gangster.tscn")

var enemy_alive = 0
var current_wave = 1
var enemies_per_wave = 3

func _ready():
	spawn_wave() #initial wave

func _on_player_health_depleted():
	#%GameOver.visible = true
	#%GameOver/ColorRect/Game_Over.show_final_score()
	get_tree().paused = true
	print("Game Over")

func are_enemies_remaining():
	enemy_alive = get_tree().get_nodes_in_group("enemies").size()
	#print(enemy_alive)

func spawn_enemy():
	print("enemy spawned")
	var new_enemy = gangster.instantiate()
	new_enemy.add_to_group("enemies")
	add_child(new_enemy)

func spawn_wave():
	for i in range(current_wave * enemies_per_wave):
		spawn_enemy()

func wave_system():
	if enemy_alive == 0:
		current_wave += 1
		spawn_wave()

func _on_timer_timeout():
	are_enemies_remaining()
	wave_system()

Hello. i’m trying to spawn multiple enemies at the same time for a wave system for a game im working on, but only one enemy spawns at one time.

When the game starts, only 1 enemy gets spawned instead of 3, even though the spawn_enemy function does get run 3 times (the output console prints out “enemy spawned” 3 times).

How can i fix this? Thanks.

Is it possible that all enemies spawn at the same location, and overlap one another all the time?

Yep, that’s it haha.
Thank you

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.