Hi,

I was wondering if it is possible to get the clicked collision shape from a Area2D which has multiple collision shapes as children. Currently, I have a single Area2D object which holds four collision shapes which are rectangles and one which is a polygon. My goal is, to get the clicked shape (or it's name) when the player clicks on one of them.

When all shapes would be rectangles I could simply use the shape_idx, provided by _on_Area2D_input_event function, but when I add polygons to the Area2D it's no longer working, because one polygon can contain multiple indices.

func _on_Area2D_input_event(viewport, event, shape_idx): if event is InputEventMouseButton && event.pressed: #print(shape_idx) if shape_idx == 0: print("0") if shape_idx == 1: print("1") if shape_idx == 2: print("2")

@Zelta said: func _on_Area2D_input_event(viewport, event, shape_idx): if event is InputEventMouseButton && event.pressed: #print(shape_idx) if shape_idx == 0: print("0") if shape_idx == 1: print("1") if shape_idx == 2: print("2")

The problem is, that this only works if I don't use polygons.

@Zelta said: it works. test it.

Not really. Like I said, when I add a polygon it's not working anymore, because a polygon can contain multiple indices.

For example:

When I print the shape_idx and click on the different polygons I get this results: Click on rect with ... "1" -> 0 "2" -> 1 "3" -> 2 "4" -> 3

So far no problem, I could easily increment the index to get the right value, but now the problem:

Click on polygon with ... "5" -> 4 "5" -> 5

I get two different indices, because its splitted in two parts.

dont split or use another area and keep going.

Yeah, I know that I could just use multiple Area2Ds, but than I would also need multiple scripts or multiple functions inside one script to handle them. That's why I was looking for a solution, where I can simply check the name of the collision shape and do some action based on that.

2 years later