0 votes

So in my last question in this Q&A(just look the node tree), I was confused why it didn't work, now I made only a scene with the bare minimun nodes to replicate the other issue, and I found out that the TextureRect I have, blocks que collisionshape in some sort of weird way, my intention was to drag a card around the screen, I used TextureRect because I do not have sprites that fit into the box and texturerect does that job for me, well, after attaching the Area2D to itself with the signals mouse in/out and in it's script:

extends Area2D

var mouse_in = false

func _process(delta: float) -> void:
    if mouse_in && Input.is_action_pressed("left_mouse_click"): #This works smoother instead of the Input.is_mouse_button_pressed() idk why

        self.position = get_global_mouse_position()
func _on_Carta_mouse_entered() -> void:
    mouse_in = true

func _on_Carta_mouse_exited() -> void:
    mouse_in = false

In other words, what I'm trying to achieve is move a node that has an Area2D + CollisionShape2D + TextureRect(Same size as collisionshape) and be able to click and drag the node/card through the screen. It has something to do with the TextureRect for sure but I can't find what is going on.

Also add debug prints in the code signals and you will found out that they only execute when clicking and holding the mouse, then drag inside the area, and then release the click, which results in a IN OUT print at the same same time.

Screenshot of the code: enter image description here
Screenshot of the scene: enter image description here

in Engine by (104 points)

1 Answer

+2 votes
Best answer

What your experiencing has to do with this:
https://docs.godotengine.org/en/3.1/tutorials/inputs/inputevent.html
Specifically with the event handling heirarchy:
Hierarchy of event handling, read left to right.

Because the TextureRect is covering the Collision2D, it runs a test for Control input first, then runs unhandled_input and winds up setting the event to handled, blocking the event from propogating to the Collision handling expected below it. If you turn the mouse filter on all of your Control based nodes (everything with green icons, the TextureRects and the Labels) to false, it should ignore the event entirely and let you interact with the Collision2D.

by (65 points)
selected by

Thanks, didn't know about the order of events, changed that to false and it worked great. ^^

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.