Input on Area2D node (child of viewport) does not work

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

Hello,

I have a problem with input on an Area2D node which is a child of a viewport. (Godot v3.1.1.stable official)

A test setup works fine:

-DemoViewport (Node)
--Area2D (has GDScript and CollisionObject2D:input_event connected with _on_Area2D_input event)
---Sprite
----CollisionShape2D

GDScript of Area2D:

extends Area2D

func _on_Area2D_input_event(viewport, event, shape_idx):
	if event is InputEventMouseButton && event.pressed:
		print("_on_Area2D_input_event")
	

Result:
As soon as I click on the Area2D the output in the console is

_on_Area2D_input_event

Now I change the project setup to:

-DemoViewport (Node)
--ViewportContainer
---Viewport
----Area2D (has GDScript and CollisionObject2D:input_event connected with _on_Area2D_input event)
-----Sprite
-----CollisionShape2D

No changes in GDScript or the connection

Result:
The function “_on_Area2D_input_event” will be never called.
If I understand correct, the viewport consume the input events but I could not find any configuration so the input event of the Area2D node is triggered again.
Where is my mistake? :frowning:

:bust_in_silhouette: Reply From: Zylann

I tried to reproduce this, and even after checking Object Picking in the Viewport properties, I can’t seem to get any input from areas specifically inside a viewport. GUI inputs or buttons work fine. That could be a bug…
…or not?
See https://github.com/godotengine/godot/issues/26181

Thank you for the link. I will follow the discussion on github.

mrkaio | 2019-08-07 13:31

I have one additional question. I think I can implement a workaround for this problem but to be able to do this I need to identify which viewport send the event to a child in the tree.

My plan is to extend the GDScript of Area2D:
func _input(event):
#do some stuff

But it looks like the event does not contain any information about the viewport…

mrkaio | 2019-08-29 15:12

If you receive an event from _input, that event comes from the viewport the node is child of, so I would say use get_viewport()?

Zylann | 2019-08-29 17:29