Area2D detects mouse hovering, but not clicks

Godot Version

4.3

Issue

Hi, making a point-and-click game. I was about to create a system so that the player could look left, allowing them to see the leftmost corner of the room. You’ve probably seen that in a lot of escape room games. Problem is, the button doesn’t detect when it is clicked.
The reason I am so stuck is because the nodes being used, the signals and the script are exactly the same for the items that the player can interact with, and those work perfectly. I don’t understand why it’s not working with this one in particular.
It’s a Sprite2D (for the button’s sprite), with an Area2D child named leftArea, and the area’s child being a rectangular CollisionShape2D. Area2D sends an input event signal to my main script:
image

func _on_left_area_input_event(viewport: Node, event: InputEvent, shape_idx: int) -> void:
	if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT:
		print("clicked!")

And nothing happens. It’s not supposed to just print, I just wrote that to check if it was working; it doesn’t even do that. Nothing shows up on my output window.
What is puzzling me so much is that this script, particularly the beginning of it, is identical to the ones for my objects. Here’s a mug you can click on as an example.
image

# COFFEE MUG
func _on_mug_area_input_event(viewport: Node, event: InputEvent, shape_idx: int) -> void:
	if !detail_selected and event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT:
		$dialog.visible = true
		detail_selected = true
		$dialog/label.text = "An old, slightly cracked coffee mug. The liquid has completely evaporated, though some powder still lies at the bottom. A cockroach seems to have stolen some. It looks content."
		dialoganim()

It works flawlessly.
(‘detail_selected’ is triggered when there is a dialog box, so it prevents the player from clicking something else during dialogue and possibly glitching the game. I removed it for the look left button in order to test it. I have tested it with “if !detail_selected” present; result is the same, no clicks detected.)

They are all under my main script, they all work essentially the same way, the only difference is that my objects don’t have sprites attached to them because the objects were drawn in the background itself (since I don’t intend for them to be picked up). But I also tested with the leftArea as a child of the root instead of the sprite and, again, the result is the same. I cannot figure out why this specific Area isn’t working when it is identical to all my other ones and all of the other ones are working fine.

Is the order in which a signal is placed in the script relevant? I played around with that, moved it around, nothing. Is the order of nodes inside the tree relevant? I also moved it as well, nothing. I put the button inside a Node2D called “move” which also houses two other areas which let you enter other rooms (one leads to the kitchen, as an example); and guess what, they work. It’s… Literally just these that don’t. Out of all of them. (I’m testing just the one for looking left right now, but the right one doesn’t work either.)
image

I don’t know if it’s the Area that is the problem because it does detect when the mouse enters it. I have a few simple functions for changing the mouse’s icon, attached the mouse_entered and mouse_exited signals to the correct ones, and it works. So it does detect when the mouse hovers over it, but not when it clicks.

Would using an actual Button node work? I don’t see why that would be needed when, again, everything else has been working normally. Genuinely lost here.

Is the area pickable set as true?
Have you set at least one collision layer?
Are any other areas overlapping it? Only the top layer will get a mouse event.
Are any control nodes overlapping it? If so make sure the mouse filter is set to Pass.

Honestly, there are tons of potential issues with this. The mouse click is probably being picked up by something else and not passing it on.

Anyway, I hope that helps in some way.

PS your area will be scaled with your sprite which can cause problems. This is a strange way to do a button, you would probably be better to use a button.

PPS Make sure your signal is connected to the node properly. Do you get the little green connected marker? Does the nodes signal actually go to the method you think it is going to? Right click the signal in the inspector and click ‘go to method’ to check.

mouse_entered/exited only triggers if that is setted, so will be.

Areas work different from Controls, if areas overlaps both will receive the event.

As the other one, if some Control is stealing the input, mouse_entered/exited will also not trigger.


The only thing i can think is if you’re using get_viewport().set_input_as_handled() somewhere, so that would stop the event propagation if some area get the input first, otherwise only with the project in hands to investigate further.

I’m not using that anywhere, I believe. What’s strange to me is that nothing is overlapping the area either It is pretty far away from the rest.

image

Signals are connected, yes. I even re-connected, same problem. I’ll try to use an actual Button – it’s still weird that everything else works fine except for this particular thing.

UPDATE: It… Fixed itself. I don’t even know what happened. It wasn’t anything in the Inspector, not the placement in the tree nor script… Honestly I should be happy, and I am, but it’s not exactly satisfying. I did restart my computer due to an unrelated issue I was having – could this have done it? But I can’t see how that would be the case since this problem actually happened yesterday, I just decided to post about it this morning.

Though I did realize a completely different issue which I don’t know if I should make a post about. Godot is not printing anything to my output. I don’t think this was the problem either because I did test the actual code, for the thing the button was supposed to do, and it didn’t work… Until it did. Sigh.

Maybe it’s something I did which I just never noticed. Regardless, thanks for all the help. Not even sure if I should mark this as solved since there was no actual concrete solution :face_with_spiral_eyes: let’s just hope this doesn’t happen again.

1 Like