This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
+1 vote

To be more specific, I’m trying to make a door disappear when the count of enemies that are children of a node reaches 0 so you can access the exit, but I don’t understand how to, I’m not even sure which node to attach the script to that knows the number of enemies.

in Engine by (28 points)

You should research AutoLoad and Singletons

1 Answer

+2 votes
Best answer

Sorry for that answer but I found another better solution

var enemy_parent = $Enemy_Parent #Reference to enemy's parent
var door_node = $Door #Door Reference
var enemy_count = enemy_parent.get_child_count()
print("enemy count: " +  str(enemy_count))
if enemy_count == 0:
    door_node.hide()

Only set the reference to the nodes. The number of childs would be counted automatically by get_child_count()

by (942 points)
selected by

for some reason my enemies have now all turned invincible after doing this

never mind, what happened was that I tried to pass globals into a function because I forgot to make it auto load because I was gonna do an autoload with a different script, testing it after removing that, the enemies die now, I'll test to see if the door opens when they all die.

This still doesn't work

When all enemies die then (how will the door know if it should hide or not).
So attach a script to Door node and use this:-

func _process(_delta):
    if Globals.enemy_count == 0:
        hide()

Thanks a ton man, I had to change hide to queue_free so the collision shape disappears too, but you were a huge help, I was worried I’d have to make some big change in the game to make it work without some way to ensure you killed all the enemies in the level which is the only way I could think of to get the player to explore with my extremely limited knowledge of game design and coding, gimme a sec to select this as the answer

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.