Area2D not behaving as expected inside a control node

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

Hello Godot community,

Below is the structure I’m having :
------> Area2D
------------> TextureRect
------------> CollisionShape2D

When I connect the inputevent signal of my node Aread 2D to the main gd script (in the same scene), the follow code is not working :

func _on_DominoePieceA2D_input_event(viewport, event, shape_idx):
	if (event is InputEventScreenTouch):
		if (event.is_pressed()):

I do receive an event, but is_pressed returns false, moreover, it’s not working when I export it on phone.
So I was wondering if the structure I’m having (control and Node2D) is a valid structure.

What I’m trying to do is having images in a container, I’m trying to perform a drag&drop/click on those in order to move them into another container, so if my implementation is not valid, I’m open for suggestions :).

Thank you for any help.

:bust_in_silhouette: Reply From: Jowan-Spooner

Hi Seli,
I would recommend using Texturerects without Areas and collision-shapes. Areas are mostly for receiving information from other physics driven elements (like collisions or if a body enters). You can use gui_input(event) signal. You should also have a look at the GUI Drag and Drop Demo. If you have any further questions of how to use this tips feel free to ask.

Good luck. Jowan-Spooner

P.S. I don’t know why what you do is not working and it’s porbably not completely wrong and should somehow be possible, nevertheless the way I described above is more common for what you seem to try.

:bust_in_silhouette: Reply From: limiteegod

I struggle for the same problem as well And I think what you write is right! The problem is that The Event System…
The event is consumed by UI elements and not be sent to Physic world. That is the dot engine design And I think that is wrong in 2d games.
The best practise is to test any event in UI and physic world all and select the nearest (ui element OR physic object) to trigger the event. OR the UI element can consume the EVENT and then resend to the physic world. Both is OK(This way, the problem is some event will not fit like body_enter event, the parent UI shape is not the same as child Area2d, But the init event like mouse move is ok).
Thanks, I think the dotengine should fix this.
3d Game is the same, need a function that can resend the init event to physic world.