Instantiated bodies and Area2d

Godot Version

4.3

How do you make an instantiated body to trigger an Area2d signal?

So, I wanted to make a Chracterbody2d jump as it entered an Area2D, it worked just fine. Then I tried to make this Character spawn in the scene instead of starting there. I set up the instantiate code, it spawns, but now it just doesn’t trigger the body_entered signal.

I think the problem is that the Area2d is sending a signal to a node that doesn’t exist in the scene anymore, but I don’t know how to fix this. I’m new to godot (and programming as a whole) so forgive me if this is a dumb question.

You need to connect the signal in this way:

area_2d.body_entered.connect(player._on_body_entered())

This is just the structure of connecting a signal, now in this way you can fix that.

Here is a detailed structure:

node.signal_name.connect(any_optional_node.to_function())
1 Like

So I should connect it in the CharacterBody2d script? I’ll try that, thx!

1 Like

It would better if you connect them in the main script, where you instantiated the player.