Stopping Area2D mouse signals from propagating

Godot Version



I have a following helper node made for handling clicks:

class_name ClickHelperScene
extends Area2D

signal clicked_left_mouse_button
signal clicked_right_mouse_button
signal mouse_hover_start
signal mouse_hover_end

func _ready() -> void:

func _input_event(viewport: Viewport, event: InputEvent, _shape_idx: int) -> void:
	var is_event_mouse_click: bool = \
		event is InputEventMouseButton and event.is_pressed() 
	if is_event_mouse_click and event.button_index == MOUSE_BUTTON_LEFT:
	elif is_event_mouse_click and event.button_index == MOUSE_BUTTON_MASK_RIGHT:

And this works fine… Well, mostly. Thing is, I’m making a card game, and the cards use this to react to mouse events but sometimes cards overlap over one another, like this:


Clicks work fine since I handle them via viewport.set_input_as_handled(), but same doesn’t go for mouse hover. Is there a way for me to handle an mouse hover event so it doesn’t propagate to Area2Ds below it, similar to clicks (there is probably a manual way of detecting some sort of InputEventMouseMotion but that seems hacky to me)? As you can see in the code above, I tried handling input manually on area’s mouse_entered and mouse_exited signals, but doesn’t do anything as far as I can see.

Cards, when hovered

Any advice on handling this neatly would be awesome.

Another solution that comes to mind is to have a system where nodes of the similar node groups (let’s say cards in this case) that allows only one of these elements to be selected/hovered etc (either via some sort of event bus or singleton).

Also I’ve stumbled across another post which covers similar issues.

Seems like there’s really no easy way out…