Change level when all enemy dead

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

How can i make to change the scene when all the enemies are dead?

:bust_in_silhouette: Reply From: lewis glasgow

put all enemys in a node2D and call it enemies, assuming when enemies get killed they deleted from the game ( queue_free() )

func _process(delta):
	if $enemies.get_child_count == 0:
		get_tree().change_scene("your next level")
:bust_in_silhouette: Reply From: danielhernandez

You can add each enemy (I suppose there’s a Enemy scene) to a group, “enemies” for example.

Then, you can check how many nodes there are in the group:

func _process(delta):
  var enemies = get_tree().get_nodes_in_group("enemies")
  if enemies == 0:
    go_to_next_level()

Of course, for this to work, you have to remove the enemies as they die with queue_free().