Area input_event not working when created from code

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By TobiLa

Hey,
when I use the editor to create an area node and attaching this script, the _on_area_input_event is called properly:

extends Area


func _ready():
    var rectangle_shape = BoxShape.new()
    rectangle_shape.extents = Vector3(500, 500, 2)
    var collision_shape = CollisionShape.new()
    collision_shape.shape = rectangle_shape
    self.add_child(collision_shape)

    set_ray_pickable(true)

    connect("input_event",self,"_on_area_input_event")

func _on_area_input_event( camera, event, click_pos, click_normal, shape_idx ):
   pass # replace with function body

When I create the same node with the same translation etc from code by calling

var test = preload("res://test.gd")
var newTest = test.new()
# setting translation etc
[...]
add_child(newTest)

The function is not called.
When viewing the live tree in the remote inspector I can’t see any difference between the nodes.

Can anyone help me to get this node working when created from code?