Z_Index Issue maybe? Mouse won't select top node, but bottom node instead. How can I work around this?

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

Hi all,

If you look at that GIF you’ll see the problem.

I can guarantee the cards coming out of the left pile and onto the right have the correct Z_Index. You can see the newest cards raise to the top and sit on top of the ones on the bottom.

Why then is the mouse not selecting the card on the top? I’m a little stumped.

Any advice greatly appreciated.

Thank you.

:bust_in_silhouette: Reply From: Christoffer

in my game i can have a few items covering each other. and my code always select the top item. take a look and maybe you can make it work for you aswell.

func _input_event(viewport, event, shape_idx):
if event is InputEventMouseButton \
and event.button_index == BUTTON_LEFT \
and event.is_pressed():
	if Global.mouse_selection and selected:
		selected = false
		Global.mouse_selection = false
		Global.object_selected = null
	elif Global.mouse_selection == false and selected == false:
		selected = true
		Global.mouse_selection = true
		Global.object_selected = self
	elif Global.mouse_selection == true and selected == false:
		selected = true
		Global.object_selected.selected = false
		Global.object_selected = self

i have a global script singleton that holds those two variables “object_selected and mouse_selection”

EDIT: and by the way, my item scene contains area2d, collision shape and a sprite