+2 votes

I am trying to migrating my old drag and drop script to Godot 3 and found "input_event, mouse_entered and mouse_exited" for Area2D in not connecting.

Except CollisionObject2D events other events are working fine for Area2D.

The Script was working fine in **Godot 2.***.

Following is the sample code I used to test.

func _ready():
    var dd = get_node("Area2D").connect("input_event",self,"_on_Area2D_input_event")

func _on_Area2D_input_event( viewport, event, shape_idx ):
in Engine by (29 points)

3 Answers

+4 votes
Best answer

I fixed this my own by replacing root node from Container to Node2D.

The CollisionObject2D events not working if we place any control object (Container, Panel, TextureRect, etc.) as root node (I don't know the reason but it was worked well in Godot 2).

Edit 1:

As instructed by literalcitrus
mouse_filter = MOUSE_FILTER_IGNORE
fixed the issue without changing the type of root container.


by (29 points)
selected by

The Container was eating the events and never reached the Area, look at input events in the documentation to see how that works.


Check the mouse_filter property of the root Container node. Changing that around might solve the initial problem. You can check the MouseFilter enum here: http://docs.godotengine.org/en/3.0/classes/class_control.html

Yes, you are right.. It works fine after I set property

mouse_filter = MOUSE_FILTER_IGNORE for root container.


0 votes

It works fine.
This could be caused be thousands of reasons, but it's not the code.
Make sure the Area2D is set to Pickable.
Make sure your Collision is properly set.
And next time post more info.

by (1,104 points)

Thanks for your suggestion.

+1 vote

I encountered the same problem.
Check "Project Settings -> Physics -> Common -> Enable Object Picking", must be "enabled".

by (20 points)
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 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 webmaster@godotengine.org with your username.