Best way to process mouse action on overlapping nodes

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Korinin

I have a “game board” (TileMap), where chips are moved with mouse, and GUI that overlaps this “game board” sometimes.

I need that if I clicked (or did anything else) while mouse position was above GUI, it wouldn’t interact with “game board” below GUI in that position.

Any ideas?

“The best” solution (which I don’t like but it worked until the last moment) I could invent was to simply ask every GUI node “Is mouse over you?” recursively:

func is_mouse_over():
for child in get_children():
	if child.is_mouse_over():
		return true
return (get_rect().has_point(get_local_mouse_position())

The problem is, I have to manually attach this script to every single GUI node and manually remove last line in nodes that don’t have Rect2. Apart from this, it looks ugly

Korinin | 2020-08-06 06:44

:bust_in_silhouette: Reply From: Varden

Read this article Using InputEvent — Godot Engine (stable) documentation in English
I think you just need to use _unhandled_input() for your chips on TileMap instead of using _input() or even _process(). But I recommend you to understand how inputs are handled, it can help you a lot in future.

Thank you, I’ll look into it

Korinin | 2020-08-06 11:27