Signals form a dynamically created Child Note

Godot Version

4.1.2

Question

I already know how to create a Signal from a Scene that exits at the start of the game:

What I don’t know is how to get a signal from an Instance of a Scene that was created during the game.

As a practical example:

In a shotting game I would know how to have the player Scene create a bullet in the level. That is easy the Player is in the level from the start of the game.

But I also have Enemies that are not there for the start of the game but get created at random intervals. I use instantiate of a PackedScene to create each enemy and add them with add_child to a holder Note.

If I want these Enemies to leave blood splatters on the floor. For that I need to send a signal to the level. This is what I don’t know how to do. Can anyone help me?

I let this problem sit there for a while so I am a bit rusty on my Godot knowledge.

When you instantiate the enemies you can access their signals:

var enemy = ENEMY_PACKED.instantiate()
enemy.your_signal_name.connect(method_to_connect_to)
...

func method_to_connect_to():
    # do blood-splatters
2 Likes

Thank you seems to work perfectly.