How to add a _on_Area2D_input_event signal to a instantiated CollisionShape2D node with code

Godot Version

godot v4.2.1

Question

How to add a _on_Area2D_input_event signal to a instantiated CollisionShape2D node with code

I’m trying to make a card game where I want to move a sprite with the mouse. The sprite node has an Area2D and CollisionShape2D as children, and I’m using the _on_Area2D_input_event signal. However, since the nodes are instantiated at runtime, I can’t connect the signal in the editor. I’ve tried different approaches but haven’t been able to make it work for example

get_node(collisonArea2dnode.connect(“_on_area_2d_input_event”,get_node(collisonArea2dnode).function)

but i get an an error that the function is a null insance when i run the game i dont really understand how to use .connect()

The new format for connecting a signal is:

node.signal_name.connect(whatever_function)

The way you connected the signal is for Godot 3 not 4. You can check docs for more information.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.