- Edited
Hi! I'm stuck with something that should be simple...
I'm trying to create an area2d that can be clicked to run a func. It should work with the signal _Input_Event, but the game doesn't handle my clicks.
This is the code that should work:
func _on_troli_input_event(viewport, event, shape_idx):
if (event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT and event.pressed):
print("click")
Here is some weird behavior I noticed:
- It only works when I click the exact time the pointer enters the Area2D.
- If I print(event) , I get it as an InputEventMouseMotion instead of InputEventMouseButton:
"InputEventMouseMotion: button_mask=1 (Left Mouse Button), position=((696, 721)), relative=((0, 0)), velocity=((0, 0)), pressure=0.00, tilt=((0, 0)), pen_inverted=(false)" - As you can see, the event doesn't have a button_index to indicate it's the left click. This is probably because it's not an InputEventMouseButton.
- If I run the code in
func _Input(event):
, my clicks are detected correctly as InputEventMouseButton and have a button_index. - The mouse wheel is the only input detected as an InputEventMouseButton. If I print(event.button_index) it returns 4 for UP and 5 for DOWN.
Thank you so much for any possible help!
Edit: The code worked fine in a new Godot Project. But it doesn't work in my project even in a new scene with only the area2D...
Solved: I had a global transition screen (Autoload) with a ColorRect set to visible that was blocking my input. I had to reconstruct my whole project to find that out because Godot's option to disable Autoloads doesn't seem to work!