The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes

So I'm making levels for a 2D platformer. One of the things I decided to add at the beginning of a level is a Life Screen scene that plays before you can play the level. Basically like in Super Mario Bros., where there's a screen that tells you what level you're about to play, how many lives you have, current score, etc. While this screen is displayed, I don't want enemies to move, so that if I have a level where an enemy is on-screen and on the same level as the player, the player doesn't get hit at a time where player input is disabled. My solution to this is to auto-set the enemy script to idle, and only be given permission to move once the life screen is gone. Basically, here's the logic:

  • Scene starts
  • Life Screen timer autostarts
  • Timer ends
  • Signal gets sent
  • Life Screen disappears

The issue: I have to individually connect the signal to each individual instance of an enemy. It's not auto-connected to all enemies, so every time I generate a new enemy in a level, I have to connect the signal to the new instance, otherwise the new instance is stuck in idle mode. This can be time consuming, and frustrating when I forget to connect it to a new instance. I just want to know if there's a way of automating the process so each new instance could be auto-connected to the signal.

Godot version 3.2
in Engine by (14 points)

1 Answer

+1 vote

Instead of sending signals to all the enemy instances at once, you can use groups! In the enemy code's ready function, you can use


This line of code will initialize the group when it is called for the first time. If you have a game controller script of some sort (likely where you were calling the signal from), you can use

get_tree().call_group("enemies", "a function").

Obviously you replace "a function" with whatever you need to call. You can make a function for all the cases, such as disabling the collisions on start up, and so on.

Hope this helps!

by (40 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.