#is_action_pressed function don't work with area2d object

1 messages · Page 1 of 1 (latest)

dusk cliff
#

Hello!
I have the Area2d object with Sprite and Collision objects under it. I created the script that should listen to the left click of the user and send a log message on action. But it doesn't show the message. I created the input map left-click action. I attached the script to the Area2d object(Deck). Please help)
Code:
extends Area2D

func _input_event(_viewport, event, _shape_idx):
if event.is_action_pressed("left_click"):
print("Deck clicked!")

bright flint
#

did you define an action "left_click" in your project? Such a thing is not a default action.

#

you can write

if event is InputEventMouseButton and event.button_index == MouseButton.MOUSE_BUTTON_LEFT: print("clicky")

the docs are here

dusk cliff
#

yeah, in the Input Map. I have it on screenshot

bright flint
#

confusingly in that screenshot, left_click is defined as a physical right click

#

were you testing with right click?

dusk cliff
#

ohhh, but with left mouse it also didn't work

bright flint
#

doesn't matter; with left mouse it is not defined to work

#

does it work with right click? 🙂

#

the next thing to try is to check the debugger tab "misc" and see where your event is actually getting dispatched; perhaps a control along the way is on top of the area and eating the click

#

but certainly as it's currently defined you're only listening for right clicks 🙂

dusk cliff
#

btw, thank you very much for answering!

bright flint
#

so that's saying "Main" ate your click. Do you have a script there that reacts to clicks, or is it just saying "I couldn't figure out where to send the click"?

#

consider print(event) (before the if) just to see if any events ever get routed here.

dusk cliff
bright flint
#

ok, so it's not calling your _input_event at all.

Note: _input_event() requires input_pickable to be true and at least one collision_layer bit to be set.
from the docs; is that the case? Show your scene tree too plz.

dusk cliff
#

yeah, the pickable is set to true in Deck(area2d) object and some layers are there too

#

btw, the function _input works

bright flint
#

I bet that's true but you actually haven't shown me the layers (they're under Collision)

dusk cliff
#

or its in the visability tab?

bright flint
#

Yeah, ignore visibility; that's different!

#

Anyway. What's mouse filter set to on your Main (the root)?

#

It's a control -ish property

dusk cliff
bright flint
#

Ahah! Make it Ignore

#

Then everyone should just work iiuc

#

(or make your main a node2d instead of control)

dusk cliff
#

lol, really worked

#

ty so much!

#

btw, when i make my main node 2d the objects in it just don't scale to the window sizw automatically. Even with resizing with anchor presets. Thats why I use control as a root node