+1 vote

Hey,
when I use the editor to create an area node and attaching this script, the onareainputevent 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?

in Engine by (205 points)

Please log in or register to answer this question.

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.