0 votes

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

in Engine by (17 points)

2 Answers

0 votes

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")
by (458 points)
0 votes

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:

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

by (22 points)
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.